I'm trying to remove an observation in an array via indexing. What I have is:
import numpy as np
test = np.ones([1, 1001])
What I want to do is return an array that is the same as test, but having removed the 5th observation (ie, test[0:4 AND 6:]). Is there a simple way to do this?
You could use slicing and hstack:
In [18]: test_ex5 = np.hstack((test[:,:5],test[:,6:]))
In [19]: test.shape
Out[19]: (1, 1001)
In [20]: test_ex5.shape
Out[20]: (1, 1000)
Note that your indexing is off by one: test[0:4 AND 6:] would delete two elements instead of one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With