code: def corruptSparseVector(sdr, noiseLevel):
    
  
    numNoiseBits = int(noiseLevel * np.sum(sdr))
    if numNoiseBits <= 0:
      return sdr
    activeBits = np.where(sdr > 0)[0]
    inActiveBits = np.where(sdr == 0)[0]
  
    turnOffBits = np.random.permutation(activeBits)
    turnOnBits = np.random.permutation(inActiveBits)
    turnOffBits = turnOffBits[:numNoiseBits]
    turnOnBits = turnOnBits[:numNoiseBits]
  
    sdr[turnOffBits] = 0
    sdr[turnOnBits] = 1
docs: Add noise to sdr by turning off numNoiseBits active bits and turning on
    numNoiseBits in active bits
    @param sdr        (array) Numpy array of the  SDR
    @param noiseLevel (float) amount of noise to be applied on the vector.