-2

I created a multi-dimensional numpy array using this code:

pt=[[0 for j in range(intervals+1)] for i in range(users+1)]

A `print (np.shape(pt)) gives me

(1001,169)

I then proceeded to populate the array (code not shown) before trying to select everything but the first column to feed into matplotlib.

I referred to posts on how to select columns from a multi-dimensional array: here here and here

all of whom say I should do:

pt[:,1:]

to select everything but the first column. However this gives me the error message:

TypeError: list indices must be integers or slices, not tuple
3
  • 1
    This seems like a list, not a numpy array... Commented Jun 14, 2017 at 10:00
  • Why not simply numpy.zeros((users + 1, intervals + 1), dtype=int)? Commented Jun 14, 2017 at 10:08
  • @Markus - You are absolutely correct. I just realized this. People like this (i-programmer.info/programming/python/…) are to blame. For goodness sake don't say "For a programmer moving to Python the problem is that there are no explicit provisions for multidimensional arrays. As a list can contain any type of data there is no need to create a special two-dimensional data structure. All you have to do is store lists within lists". Commented Jun 14, 2017 at 10:13

1 Answer 1

0

Anyone else that reaches this post from having made the same mistake (see comments above), if you want to continue using lists then do pt[:][0:1] but really I recommend switching to numpy and ignoring all the results you get when you search for 'declaring python array'

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.