0
0
NumPydata~5 mins

Correlation with np.correlate() in NumPy - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the function np.correlate() compute?

np.correlate() computes the cross-correlation of two 1-dimensional sequences. It measures how similar two sequences are as one is shifted over the other.

Click to reveal answer
intermediate
What is the difference between correlation and convolution in numpy?

Correlation compares two sequences by sliding one over the other without flipping. Convolution flips one sequence before sliding. np.correlate() does correlation, while np.convolve() does convolution.

Click to reveal answer
beginner
What does the mode parameter in np.correlate() control?

The mode parameter controls the size of the output:

  • 'valid': Only positions where sequences fully overlap.
  • 'same': Output is the same length as the first sequence.
  • 'full': Includes all overlaps, even partial.
Click to reveal answer
intermediate
How can np.correlate() be used to find a pattern in a signal?

By correlating the signal with the pattern, peaks in the result show where the pattern matches the signal best. This helps detect the pattern's position inside the signal.

Click to reveal answer
beginner
What is the shape of the output when using np.correlate(a, v, mode='full') if a has length n and v has length m?

The output length will be n + m - 1. This includes all possible overlaps of the two sequences.

Click to reveal answer
What does np.correlate(a, v, mode='valid') return?
AAn output with the same length as <code>a</code>
BThe full correlation including partial overlaps
COnly the parts where <code>a</code> and <code>v</code> completely overlap
DThe convolution of <code>a</code> and <code>v</code>
If a = [1, 2, 3] and v = [0, 1], what is the length of np.correlate(a, v, mode='full')?
A4
B3
C2
D5
Which numpy function flips one sequence before sliding for comparison?
Anp.correlate()
Bnp.convolve()
Cnp.dot()
Dnp.cross()
What does a peak in the output of np.correlate(signal, pattern) indicate?
AA strong similarity or match at that position
BA mismatch between signal and pattern
CThe length of the pattern
DThe sum of signal values
Which mode in np.correlate() gives output length equal to the first input's length?
Avalid
Bnone
Cfull
Dsame
Explain in your own words what np.correlate() does and how it can be used in real life.
Think about how you might find a small sound or pattern inside a longer recording.
You got /4 concepts.
    Describe the effect of different mode options in np.correlate() and when you might use each.
    Consider if you want only exact matches or partial matches included.
    You got /4 concepts.