I am learning Python and numpy, and I am new to duck print idea. I am writing functions in which something / someone should pass a numpy array. Trying to declare duck print, I write my code to use numpy.array with copy= and ndmin= parameters to convert arrays array_likes or 1d / 0d to the form I need. In particular, I use the ndmin= parameter in cases where I can accept either an array (p,p) or a scalar; a scalar can be encoded as an array int , (1,) , array (1,1) , [1] , etc ...
Therefore, to take care of this, I use something like S = numpy.array(S,copy=False,ndmin=2) to get the array (if possible) using the correct ndim , and then check the form as I need . I know that I have to insert this into the Try-Except block, but I can not find any documentation about what numpy.array() exception might be. So I now have this:
What specific exception (s) should I try to catch here? Thanks.
source share