By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,009 Members | 2,859 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,009 IT Pros & Developers. It's quick & easy.

indexing arrays

P: n/a

I'm having trouble slicing arrays:

I thought I could do the following:
>>i = array(range(140,149))
j = array(range(5,20))
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

It's strange, because I can do this:
>>a = acc[140:148,5:19]

Anyone know what I am doing wrong?

--
View this message in context: http://www.nabble.com/indexing-array...p19918073.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Oct 10 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"John [H2O]" <wa******@gmail.comwrote in message
news:ma**************************************@pyth on.org...
>
I'm having trouble slicing arrays:

I thought I could do the following:
>>>i = array(range(140,149))
j = array(range(5,20))
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

It's strange, because I can do this:
>>>a = acc[140:148,5:19]


Anyone know what I am doing wrong?
What data structure is acc, and what are you trying to do?
Oct 10 '08 #2

P: n/a
John [H2O] wrote:
Anyone know what I am doing wrong?
The arrays in the numpy package are more sophisticated than the built-in
array package. This sort of thing works there:
>>import numpy
a = numpy.array([1,2,3,4,5,6,7,8])*2
a
array([ 2, 4, 6, 8, 10, 12, 14, 16])
>>a[range(3,6)]
array([ 8, 10, 12])

Jeremy

--
Jeremy Sanders
http://www.jeremysanders.net/
Oct 10 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.