0

I'm trying to build a model from an array with 572 rows and 8 columns loaded with NumPy. Define the sets using the line address for a new array:

train_x = x_vals[(11:34, 46:98, 110:268, 280:342, 354:408, 420:428, 440:478, 490:538, 550:571]

test_x = x_vals[0:10, 35:45, 99:109, 269:279, 343:353, 409:419, 429:439, 479:489, 539:549]

train_y = y_vals[11:34, 46:98, 110:268, 280:342, 354:408, 420:428, 440:478, 490:538, 550:571]

test_y = y_vals[0:10, 35:45, 99:109, 269:279, 343:353, 409:419, 429:439, 479:489, 539:549]

I'm trying to test my model with 99 samples and calibrate with 473. Although the Spyder environment accepts the declarations of the lines above, at the time of running the program it appears:

train_x = x_vals[11:34, 46:98, 110:268, 280:342, 354:408, 420:428, 440:478, 490:538, 550:571]

IndexError: too many indices for array

What is missing in the declaration of the sets above?

aman
  • 37
  • 1
  • 10
  • 1
    Where have you seen this kind of usage documented? If you have a 2d array, you can only supply 2 slices, one for each dimension. https://docs.scipy.org/doc/numpy/user/quickstart.html#indexing-slicing-and-iterating. Step back a bit, define a small array, and show us what you want to select. [mcve] – hpaulj Jun 15 '18 at 05:05
  • I'm guessing you want multiple slices in one dimension. See https://stackoverflow.com/q/34188620/901925 – hpaulj Jun 15 '18 at 05:21
  • Hello hpaulj! Thanks a lot for your answer! I am also a Matlab User. There, I just specify the ranges from the original matrix. My 4 matrices have 9 ranges each (I think it is the slice, then they are 9 silces, aren't it?) I searched a lot but I did not find your answer posted. You hit the mark !! Thank you very much!! – Fernando Schimidt Jun 15 '18 at 21:39
  • In MATLAB `x([1:4, 6:10])` works because `1:4` makes a matrix sort of like `np.arange(1,5)`, `[A,B]` concatenates matrices, together producing a list of indices. `np.r[1:5, 6:11]` simulates that syntax using a bit of trickery (it is in the `index_tricks.py` file). An important difference is that in Python `1:3` can only be used in an indexing context, never as a stand alone range generator. – hpaulj Jun 16 '18 at 00:07

0 Answers0