I want to be able to define a function as having an argument of an unspecified array. For example,
import numpy as np
def cols(np.array([]):
return len(np.array([])
Say that:
x=np.array([[1,2,3],[4,5,6]])
Then I want cols(x) to give output 3.
Note, the input must be a np.array, so please no workaround to that!
def cols(arr)? and why would you think this array gives you length of 3?len(x)is equal to 2. If you want to get the size of the nested arrays (in other words the number of columns ofx), you can usex.shape[1].