Use numpy.delete() – returns a new array with sub-arrays along an axis deleted
numpy.delete(a, index)
For your specific question:
import numpy as np a = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9]) index = [2, 3, 6] new_a = np.delete(a, index) print(new_a) #Prints `[1, 2, 5, 6, 8, 9]`
Note that numpy.delete()
returns a new array since array scalars are immutable, similar to strings in Python, so each time a change is made to it, a new object is created. I.e., to quote the delete()
docs:
“A copy of arr with the elements specified by obj removed. Note that delete does not occur in-place…”
If the code I post has output, it is the result of running the code.
Related Posts:
- ValueError: setting an array element with a sequence
- Numpy ValueError: setting an array element with a sequence. This message may appear without the existing of a sequence?
- numpy: Invalid value encountered in true_divide
- How do I create an empty array/matrix in NumPy?
- numpy matrix vector multiplication
- Convert pandas dataframe to NumPy array
- size of NumPy array
- ValueError: all the input arrays must have same number of dimensions
- ValueError: setting an array element with a sequence
- Using Numpy Vectorize on Functions that Return Vectors
- Is there a NumPy function to return the first index of something in an array?
- Numpy/Python Array Value error
- initialize a numpy array
- load csv into 2D matrix with numpy for plotting
- How to access the ith column of a NumPy multidimensional array?
- Dump a NumPy array into a csv file
- Python: find position of element in array
- numpy with python: convert 3d array to 2d
- Python: slicing a multi-dimensional array
- Add single element to array in numpy
- How to normalize a 2-dimensional numpy array in python less verbose?
- Make list of arrays in python
- Understanding NumPy’s einsum
- How to fix “TypeError: len() of unsized object”
- TypeError: Invalid dimensions for image data when plotting array with imshow()
- Numpy.dot TypeError: Cannot cast array data from dtype(‘float64’) to dtype(‘S32’) according to the rule ‘safe’
- How to get the unit vector from a numpy array
- numpy-equivalent of list.pop?
- Using numpy to build an array of all combinations of two arrays
- Efficiently sorting a numpy array in descending order?
- How to plot an array in python?
- TypeError: only integer arrays with one element can be converted to an index 3
- How to create a numpy array of all True or all False?
- How to create a numpy array of lists?
- Removing nan values from an array
- Root mean square of a function in python
- What are the differences between numpy arrays and matrices? Which one should I use?
- Numpy – add row to array
- Is there any numpy group by function?
- Mean Squared Error in Numpy?
- How to normalize a NumPy array to within a certain range?
- numpy array concatenation error: 0-d arrays can’t be concatenated
- Convert a 1D array to a 2D array in numpy
- inverting image in Python with OpenCV
- How to print the full NumPy array, without truncation?
- Sorting arrays in NumPy by column
- TypeError: list indices must be integers or slices, not str
- python numpy ValueError: operands could not be broadcast together with shapes
- How to fix IndexError: invalid index to scalar variable
- Could not install packages due to a “Environment error :[error 13]: permission denied : ‘usr/local/bin/f2py'”
- numpy division with RuntimeWarning: invalid value encountered in double_scalars
- How does numpy.newaxis work and when to use it?
- How do you do natural logs (e.g. “ln()”) with numpy in Python?
- Factorial in numpy and scipy
- Unable to plot Double Bar, Bar plot using pyplot for ndarray
- How to count the occurrence of certain item in an ndarray?
- Singular matrix issue with Numpy
- Python Pandas – Missing required dependencies [‘numpy’] 1
- ‘DataFrame’ object has no attribute ‘sort’
- TypeError: cannot unpack non-iterable int objec
- ‘End of statement expected’ in pycharm
- Python: Array v. List
- Array of arrays (Python/NumPy)
- How can I use numpy.correlate to do autocorrelation?
- How to convert a PIL Image into a numpy array?
- Overcome ValueError for empty array
- Create 3D array using Python
- Pytorch reshape tensor dimension
- Overflow / math range error for log or exp
- Creating a Pandas DataFrame from a Numpy array: How do I specify the index column and column headers?
- Overflow Error in Python’s numpy.exp function
- For loop and ‘numpy.float64’ object is not iterable error
- What are the causes of overflow encountered in double_scalars besides division by zero?
- RuntimeWarning: divide by zero encountered in log
- How to read a text file into a list or an array with Python
- RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility
- Error NameError: name ‘np’ is not defined
- NumPy array is not JSON serializable
- Does Numpy automatically detect and use GPU?
- How can I check whether a numpy array is empty or not?
- Moving average or running mean
- How to start from second index for for-loop
- Official abbreviation for: import scipy as sp/sc
- Building multi-regression model throws error: `Pandas data cast to numpy dtype of object. Check input data with np.asarray(data).`
- ImportError in importing from sklearn: cannot import name check_build
- Concat DataFrame Reindexing only valid with uniquely valued Index objects
- Replacing Pandas or Numpy Nan with a None to use with MysqlDB
- threshold in 2D numpy array
- How do I merge lists in python? [duplicate]
- Numpy Resize/Rescale Image
- How to implement the ReLU function in Numpy
- RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb
- How to install NumPy for Python 3.6
- Hashing arrays in Python
- numpy : calculate the derivative of the softmax function
- How to install numpy to Python 3.5?
- Conditional indexing with Numpy ndarray
- python numpy machine epsilon
- Function to determine if two numbers are nearly equal when rounded to n significant decimal digits
- How to zip two 1d numpy array to 2d numpy array [duplicate]