[Numpy-discussion] problem: I get an array that doesn't have a length
Pierre GM
pgmdevlist at gmail.com
Wed May 2 12:41:58 EDT 2007
On Wednesday 02 May 2007 12:27:10 mark wrote:
> Any reason NOT to have asarray(3,'d') return an array of length 1?
Because then, it would be "an array, not necessarily a float" ;) You just
noticed yourself that an array of dimension 1 is pretty much like a list,
while an array of dimension 0 is pretty much like a scalar. Keeping that in
mind, I'm sure that you can see the advantage of 0D arrays: they are indeed
arrays AND scalar at the same time...
If you need your inputs to be array or scalar and stay that way, then
the "asarray" method is the best. You can just perform some additional test
on the dimension of the array, before trying to access its length or its
size.
A 0D array as a size of 1 and a dimension of zero, and therefore no length.
A 1D array as a size of n and a dimension of 1. and a length (n).
More information about the NumPy-Discussion
mailing list