I have defined operations on 3xN
NumPy
arrays, and I want to loop over each column of the array.
I tried:
for i in range(nparray.shape[1]):
However, if nparray.ndim == 1
, this fails.
Is there a clean way to ascertain the number of columns of a NumPy
array, for example, to get 1
if it is a 1D
array (like MATLAB's size
operation does)?
Otherwise, I have implemented:
if nparray.ndim == 1:
num_points = 1
else:
num_points = nparray.shape[1]
for i in range(num_points):