adrin adrin - 5 months ago 9
Python Question

How to exclude rows/columns from numpy.ndarray data

Assume we have a numpy.ndarray data, let say with the shape (100,200), and you also have a list of indices which you want to exclude from the data. How would you do that? Something like this:

a = numpy.random.rand(100,200)
indices = numpy.random.randint(100,size=20)
b = a[-indices,:] # imaginary code, what to replace here?


Thanks.

Answer

You can use b = numpy.delete(a, indices, axis=0)

NUMPY DOCUMENTATION