Re: Why does numpy.array(a[0],b[0]) have this meaning?

2008-11-03 Thread Robert Kern

Rick Giuly wrote:

Hello All,

Case 1
This generates an error, which makes sense because the argument should
be a list of numbers:
numpy.array(10,10)

Case 2
This does not generate an error and the result is an array with a
single element:
a = numpy.array([10])
b = numpy.array([10])
numpy.array(a[0],b[0])

The only different I see here between the numpy.array call in the
cases is that
a[0] is a numpy int32
10 is an int

Why would this minor difference in integer types cause a totally
different result for the two cases - or is something else causing the
difference in results?


The second argument is for a dtype. Basically, we'll accept anything there that 
can be coerced to a dtype using numpy.dtype(). For some reason, we have an 
undocumented feature where dtype(some_array_or_numpy_scalar) will return the 
dtype of that value. Plain Python ints and floats don't have a dtype attached to 
them, so we raise an exception.


If you have more numpy questions, please join us on the numpy-discussion mailing 
list.


  http://www.scipy.org/Mailing_Lists

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list


Re: Why does numpy.array(a[0],b[0]) have this meaning?

2008-11-03 Thread Marc 'BlackJack' Rintsch
On Sun, 02 Nov 2008 23:26:24 -0800, Rick Giuly wrote:

> Case 1
> This generates an error, which makes sense because the argument should
> be a list of numbers:
> numpy.array(10,10)
> 
> Case 2
> This does not generate an error and the result is an array with a single
> element:
> a = numpy.array([10])
> b = numpy.array([10])
> numpy.array(a[0],b[0])
> 
> The only different I see here between the numpy.array call in the cases
> is that
> a[0] is a numpy int32
> 10 is an int
> 
> Why would this minor difference in integer types cause a totally
> different result for the two cases - or is something else causing the
> difference in results?

>From the `numpy.array` docstring:

Inputs:
  object - an array, any object exposing the array interface, any
object whose __array__ method returns an array, or any
(nested) sequence.

And `numpy.int32` instances have an `__array__()` method:

In [225]: ten = numpy.int32(10)

In [226]: ten.__array__()
Out[226]: array(10)

Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why does numpy.array(a[0],b[0]) have this meaning?

2008-11-02 Thread alex goretoy
just a shot in the dark.

second arg to numpy.array is of type

see numpy.array.__doc__

-nop


On Mon, Nov 3, 2008 at 1:26 AM, Rick Giuly <[EMAIL PROTECTED]> wrote:

> Hello All,
>
> Case 1
> This generates an error, which makes sense because the argument should
> be a list of numbers:
> numpy.array(10,10)
>
> Case 2
> This does not generate an error and the result is an array with a
> single element:
> a = numpy.array([10])
> b = numpy.array([10])
> numpy.array(a[0],b[0])
>
> The only different I see here between the numpy.array call in the
> cases is that
> a[0] is a numpy int32
> 10 is an int
>
> Why would this minor difference in integer types cause a totally
> different result for the two cases - or is something else causing the
> difference in results?
>
>
> -rick
>
> P.S.
> I am aware that numpy.array([10,10]) will work, but I'm trying to
> understand what is going on syntactically/semantically in the two
> cases above.
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Why does numpy.array(a[0],b[0]) have this meaning?

2008-11-02 Thread Rick Giuly
Hello All,

Case 1
This generates an error, which makes sense because the argument should
be a list of numbers:
numpy.array(10,10)

Case 2
This does not generate an error and the result is an array with a
single element:
a = numpy.array([10])
b = numpy.array([10])
numpy.array(a[0],b[0])

The only different I see here between the numpy.array call in the
cases is that
a[0] is a numpy int32
10 is an int

Why would this minor difference in integer types cause a totally
different result for the two cases - or is something else causing the
difference in results?


-rick

P.S.
I am aware that numpy.array([10,10]) will work, but I'm trying to
understand what is going on syntactically/semantically in the two
cases above.


--
http://mail.python.org/mailman/listinfo/python-list