[Numpy-discussion] problem: I get an array that doesn't have a length

Christopher Barker Chris.Barker at noaa.gov
Wed May 2 14:45:40 EDT 2007


Pierre GM wrote:
> If you need your inputs to be array or scalar and stay that way

It didn't sound like the OP wanted that. I suspect that what is wanted 
if for to always be a 1-d array (i.e. vector). To do that, I'd do:

import numpy as N

 >>> def test(a):
...    b = N.asarray(a, dtype=N.float).reshape((-1,))
...    print b.shape
...
 >>>
 >>> test(5)
(1,)
 >>> test((5,))
(1,)
 >>> test((5,6,7,8))
(4,)


-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov



More information about the NumPy-Discussion mailing list