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

mark markbak at gmail.com
Wed May 2 12:27:10 EDT 2007


OK, so in my example, I get a zero dimension array. Apparently a
feature, not a bug.
What I don't understand is why it isn't an array of lenght one? (or:
why it isn't a bug?)
Is there any use for a zero dimension array?
I would very much like it to be a one dimension array.
In my application I don' t know whether an integer, float, or array
gets passed to the function.
This is my syntax:
def test(a):
   b = asarray(a,'d')
   do something to b....
I thought this makes b an array AND a float. The atleast_1d only makes
it an array, not necessarily a float.
Any more thoughts on how to do this cleanly?
Any reason NOT to have asarray(3,'d') return an array of length 1?
Thanks,
Mark

On May 2, 5:47 pm, Pierre GM <pgmdevl... at gmail.com> wrote:
> On Wednesday 02 May 2007 11:39:29 Francesc Altet wrote:
>
> > El dc 02 de 05 del 2007 a les 09:52 -0400, en/na Pierre GM va escriure:
> > > In your example:
> > > > >>> b = asarray(3,'d')
>
> > > b is really a numpy scalar, so it doesn't have a length. But it does have
> > > a size (1) and a ndim (0).
>
> > Just one correction in terms of the current naming convention: b in this
> > case is a 0-dim array, which is a different beast than a numpy scalar
> > (although they behaves pretty similarly).
>
> Quite true, my bad.
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discuss... at scipy.orghttp://projects.scipy.org/mailman/listinfo/numpy-discussion




More information about the NumPy-Discussion mailing list