# NameError: name 'xcorr\_max' is not defined

**URL:** https://discourse.obspy.org/t/nameerror-name-xcorr-max-is-not-defined/812
**Category:** Users Mailing List Archive
**Tags:** archive
**Created:** [December 12, 2018, 8:50pm UTC](https://discourse.obspy.org/t/nameerror-name-xcorr-max-is-not-defined/812 "2018-12-12T20:50:59Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Vivek.G.Babu](https://discourse.obspy.org/user_avatar/discourse.obspy.org/vivek.g.babu/32/378_2.png) [@Vivek.G.Babu](https://discourse.obspy.org/u/Vivek.G.Babu)
#### Post date: [December 12, 2018, 8:50pm UTC](https://discourse.obspy.org/t/nameerror-name-xcorr-max-is-not-defined/812/1 "2018-12-12T20:50:59Z")

</div>

I want to execute an example code:

```python
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!

---

<div class="post-metadata">

### Author: ![calum-chamberlain](https://discourse.obspy.org/user_avatar/discourse.obspy.org/calum-chamberlain/32/268_2.png) [@calum-chamberlain](https://discourse.obspy.org/u/calum-chamberlain)
#### Post date: [December 13, 2018, 9:13am UTC](https://discourse.obspy.org/t/nameerror-name-xcorr-max-is-not-defined/812/2 "2018-12-13T09:13:09Z")

</div>

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

---

<div class="post-metadata">

### Author: ![trichter](https://discourse.obspy.org/user_avatar/discourse.obspy.org/trichter/32/226_2.png) [@trichter](https://discourse.obspy.org/u/trichter)
#### Post date: [December 13, 2018, 11:58am UTC](https://discourse.obspy.org/t/nameerror-name-xcorr-max-is-not-defined/812/3 "2018-12-13T11:58:56Z")

</div>

Hi Vivek,

first you need to import the functions with

from obspy.signal.cross\_correlation import correlate, xcorr\_max

Hope it helps!  
Tom
