[SciPy-user] scipy sclicing

Stéfan van der Walt stefan@sun.ac...
Fri Oct 10 08:28:24 CDT 2008


2008/10/10 John [H2O] <washakie@gmail.com>:
>
> Could someone explain what I'm doing wrong here?
>
>>>> i = array(range(140,149))
>>>> j = array(range(5,20))
>>>> i
> array([140, 141, 142, 143, 144, 145, 146, 147, 148])
>>>> j
> array([ 5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19])
>>>> a = acc[i,j]
> Traceback (most recent call last):
>  File "<string>", line 1, in <string>
> ValueError: shape mismatch: objects cannot be broadcast to a single shape

The shapes of your indices,

In [5]: a.shape
Out[5]: (9,)

In [6]: b.shape
Out[6]: (15,)

cannot be broadcast to a single shape.  Either give the same number of
indices in i and j, or use i[:,None] and j.

Cheers
Stéfan


More information about the SciPy-user mailing list