NameError: name 'xcorr_max' is not defined

I want to execute an example code:

a = np.random.randn(10000).astype(np.float32)
>>> cc = correlate(a, a, 1000)
>>> shift, value = xcorr_max(cc)

but it is giving the error

Traceback (most recent call last):

File “”, line 1, in

NameError: name ‘xcorr_max’ is not defined

Please help!

Hi Vivek,

Without seeing your imports for this code it isn’t clear whether you imported the xcorr_max function. This error looks like you did not import the xcorr_max function (from obspy.signal.cross_correlation import xcorr_max), can you confirm what you imported please (e.g. full code)?

C

Hi Vivek,

first you need to import the functions with

from obspy.signal.cross_correlation import correlate, xcorr_max

Hope it helps!
Tom