What I want is to find the length of every column in a 2D NumPy array.
If all the columns have the same length, this is trivial with numpy.shape. Nevertheless, if the columns have different lengths, numpy.shape doesn't actually tell me the lengths of the different columns.
a=np.asarray([[0,1],[0,1],[0,1]])
b=np.asarray([[0,1],[0,1,2],[0]])
a.shape,b.shape
((3,2), (3,))
I can get what I want fairly simply by doing something like,
lenb=[len(B) for B in b]
[2, 3, 1]
However, I feel like there must be a cleaner and quicker way to do it with NumPy?
map(len,b)?