In the function, I give a Numpy array: it can be multidimensional, but also one-dimensional
So, when I give a multidimensional array:
np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]]).shape >>> (3, 4)
and
np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]]).shape[1] >>> 4
Fine
But when I set the form
np.array([1,2,3,4]).shape >>> (4,)
and
np.array([1,2,3,4]).shape[1] >>> IndexError: tuple index out of range
Ooops, the tuple contains only one element ... so far I want 1 indicate that it is a one-dimensional array. Is there any way to get this? I mean a simple function or method without a discriminant test with ndim for example?
Thanks!
python arrays dimension numpy multidimensional-array
Covich
source share