[Numpy-discussion] About asarray (list)

Manuel Metz mmetz at astro.uni-bonn.de
Wed Aug 27 10:52:49 EDT 2008


Claude Gouedard wrote:
> Hi ,
> 
> I'm just surprised by the behaviour of numpy.asarray on  lists.
> 
> Can someone comment this :
> =====================
> a=(1)
> aa=asarray(a)
> print  aa.size , aa.shape
>>> 1   ( )
> =====================
> 
> The shape  doesnot reflect the actual size.

Because a is not a tuple, but an int !!! Try:
a=(1)
print a, type(a)

Manuel

> If a=(1,2)  there is no problem .
> =====================
> aa=asarray((1,2))
> print  aa.size , aa.shape
>>> 2   (2, )
> =====================
> ... same  for sequences:
> =====================
> aa=asarray( [1] )
>  print  aa.size , aa.shape
>>> 1  (1, )
> =====================
> 
> Thanks
> Claude Gouedard
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion




More information about the NumPy-Discussion mailing list