2

What is the fastest way to access the values that are at the opposite of a particular given slice? Some code:

import numpy as np

A = np.arange(2,100000)
S = slice(79,78954,34)
A[S] #This is all the values I do NOT want. 
A[?] #All the values I want are the values in A but not in A[S], what is ?. 
Bobby Ocean
  • 3,120
  • 1
  • 8
  • 15
  • Is it not just ```A[~np.array(range(79,78954,34))]```? I think slice works in a similar fashion to the range function and you can use numpy arrays to index other numpy arrays. – Kevin Mar 25 '21 at 02:49
  • 2
    `np.delete` does this by creating boolean mask that selects the values you want to keep. – hpaulj Mar 25 '21 at 02:59
  • @hpaulj fantastic, thanks, did you want credit? – Bobby Ocean Mar 25 '21 at 03:01

1 Answers1

0

You can also use masked arrays:

A = np.ma.array(A)
A[S] = np.ma.masked
A.compressed()
Ehsan
  • 12,072
  • 2
  • 20
  • 33