[SciPy-user] what different between array([ 1., 2., 3.])

hollowspook at gmail.com hollowspook at gmail.com
Mon Nov 27 22:25:12 EST 2006


Hi,

I just think about another silimar problem.

The code is here:
-------------------------------------
>>> a = array(range(10))
>>> a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> a[4,6]
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
IndexError: invalid index
>>> a.shape = 1,10
>>> a
array([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]])
>>> a[0,[4,6]]
array([4, 6])
>>> a[:,[4,6]]
array([[4, 6]])
-------------------------------------------
If I only want to index No 4 and No 6 in a 1-D array a. Using a[4,6] is
obviously wrong.
Under this situation, do I have to shape it to a 2-D 1-by-10 array as
shown above?
Then use a[0,[4,6]] to index them?





More information about the SciPy-User mailing list