-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
Reddspark
  • 6,934
  • 9
  • 47
  • 64
  • 1
    This seems like a list, not a numpy array... – Markus Meskanen Jun 14 '17 at 10:00
  • Why not simply `numpy.zeros((users + 1, intervals + 1), dtype=int)`? – Nils Werner Jun 14 '17 at 10:08
  • @Markus - You are absolutely correct. I just realized this. People like this (http://www.i-programmer.info/programming/python/3942-arrays-in-python.html?start=1) 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". – Reddspark Jun 14 '17 at 10:13

1 Answers1

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'

Reddspark
  • 6,934
  • 9
  • 47
  • 64