-1

I am getting IndexError if I try doing it using a for loop.

Any good way to go about it?

1 Answers1

3

Use the reshape() method on the array. (It's also avilable as a NumPy function, np.reshape().)

Try this:

import numpy as np
arr = np.random.random((10000, 10, 10))
arr.reshape((10000, 100, 1))

In general, you almost never need a loop with NumPy arrays.

Matt Hall
  • 7,614
  • 1
  • 23
  • 36