1

This is the code I have so far:

import numpy as np

#make amplitude and sample arrays
amplitude=[0,1,2,3, 5.5, 6,5,2,2, 4, 2,3,1,6.5,5,7,1,2,2,3,8,4,9,2,3,4,8,4,9,3]
#print(amplitude)

#split arrays up into a line for each sample
traceno=5                  #number of traces in file
samplesno=6                #number of samples in each trace. This wont change.

amplitude_split=np.array(amplitude, dtype=np.int).reshape((traceno,samplesno))
print(amplitude_split)

#find max value of trace
max_amp=np.amax(amplitude_split,1)
print(max_amp)

#find index of max value
ind_max_amp=np.argmax(amplitude_split, axis=1, out=None)
#print(ind_max_amp)

#find 90% of max value of trace
amp_90=np.amax(amplitude_split,1)*0.9
print(amp_90)

I would like to find the value in each line of the array that is closest to the corresponding amp_90. I would also like to be able to obtain the index of this number. Please help!

n.b. I know this is easy to do by eye, but it is a test data set before I apply it to my real data!

2
  • By closest you mean in absolute terms? What is the expected output? Commented Apr 15, 2020 at 16:29
  • Yep. Just to note that in my "real" data I wont be dealing with just integers... not sure if this matters or not Commented Apr 15, 2020 at 16:32

1 Answer 1

1

IIUC, you could do the following:

# find the indices of the min absolute difference 
indices = np.argmin(np.abs(amplitude_split - amp_90[:, None]), axis=1)

# get the values at those positions
result = amplitude_split[np.arange(5), indices]

print(result)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.