How to delete numbers from a vector?
问题 I have this vector v = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,19,20) I want to remove the multiples of 2 and 3. How would I do this? I tried to do this but I doesn't work: import numpy as np V = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,19,20) Mul3 = np.arange(1,21,3) Mul2 = np.arange(1,21,2) V1 = V [-mul2] V2 = V1 [-mul3] 回答1: Given that you use NumPy already you can use boolean array indexing to remove the multiples of 2 and 3 : >>> import numpy as np >>> v = (1,2,3,4,5,6,7,8,9,10,11