[Numpy-discussion] Shapes and sizes
Christopher Barker
Chris.Barker at noaa.gov
Fri Feb 24 15:19:05 EST 2006
Albert Strasheim wrote:
> Personally, I think asarray(scalar) should return something that can
> actually be used as an array (i.e. has a proper shape and ndim),
What is the proper shape and numdim? Only your app knows.
What I generally do with a function i want to take an array or
"something that can be turned into an array" is to use asarray, then set
the shape to what I am expecting:
>>> import numarray as N
>>>
>>> def rank1(input):
... A = N.asarray(input)
... A.shape = (-1)
... print repr(A)
...
>>> rank1((5,6,7,8))
array([5, 6, 7, 8])
>>> rank1(5)
array([5])
>>>
>>> def rank2(input):
... A = N.asarray(input)
... A.shape = (-1, 2)
... print repr(A)
...
>>> rank2((2,3))
array([[2, 3]])
>>> rank2(((2,3), (4,5), (6,7)))
array([[2, 3],
[4, 5],
[6, 7]])
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (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