472,328 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

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

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.
Nov 3 '08 #1
2 1613
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
Nov 3 '08 #2
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

Nov 3 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: mcdurr | last post by:
I recently installed Python 2.5 on Windows and also installed numpy 1.0. I'd like to compute an FFT on an array of numbers but I can't seem to...
1
by: Jianzhong Liu | last post by:
Hello, Guys, I have a question about the linear_least_squares in Numpy. My linear_least_squares cannot give me the results. I use Numpy1.0....
3
by: Duncan Smith | last post by:
Hello, Since moving to numpy I've had a few problems with my existing code. It basically revolves around the numpy scalar types. e.g. ...
4
by: jimgardener | last post by:
hi, (i posted this to numpy discussion grp couple of days back ..but it fails to appear..)since it is needed for my work i would appreciate if...
0
by: Gary Herron | last post by:
Marlin Rowley wrote: Numpy can do this for you. First, do you really mean the array to contain lists of one string each? If so: kludge here...
5
by: Marc Oldenhof | last post by:
Hello all, I'm pretty new to Python, but use it a lot lately. I'm getting a crazy error trying to do operations on a string list after importing...
2
by: sapsi | last post by:
Hello, I have a numpy array (2 rows 3 colums) import numpy a=numpy.array( , ]) I wish to add a row, this is how i do it s=a.shape...
2
by: Travis Oliphant | last post by:
I wanted to point anybody interested to a blog post that describes a useful pattern for having a NumPy array that points to the memory created by a...
3
by: Rüdiger Werner | last post by:
Hello! Out of curiosity and to learn a little bit about the numpy package i've tryed to implement a vectorised version of the 'Sieve of Zakiya'....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.