[SciPy-user] what different between array([ 1., 2., 3.]) and array([[ 1., 2., 3.]])
Zhang Sam
hollowspook at gmail.com
Mon Nov 27 06:31:17 CST 2006
Hi, there
I am a newer here. I just used numpy and scipy for a while.
I am confused about the 1-D array.
The code is as follows:
---------------------------------------------------------------------------------------------------
>>> x=array([1 ,2.,3])
>>> x
array([ 1., 2., 3.])
>>> x.shape
(3,)
>>> x[0,:]
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
IndexError: too many indices
>>> x.shape = 1,3
>>> x
array([[ 1., 2., 3.]])
>>> x[0,:]
array([ 1., 2., 3.])
-----------------------------------------------------------------------------------------------------
Typing x=array([1 ,2.,3]) will generate array([ 1., 2., 3.]). Since this
is a array variable, It should be indexd by list. However x[0,:] is wrong.
I must force its shape to (1,3), then x[0,:] will return a array.
Both x (before and after) is array class. Why the indexing method exist
difference.
What's difference between them?
If there is explaination in some document already, a link to it is ok.
Please do me a favour.
Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20061127/741f8ab5/attachment.html
More information about the SciPy-user
mailing list