'In numpy how would be convert values internally
I am new to numpy library.
How values are converted to get below output and internally how the values are changed?
>>> np.convolve([1, 2, 3], [0, 1, 0.5])
o/p: array([ 0. , 1. , 2.5, 4. , 1.5])
Solution 1:[1]
np.convolve(a, v, mode='full') function just pushes the first array a sliding on the second array v step by step from left to right. On every step, we just calculate v[i]*a and get v[i]a[0], v[i]a[1], ..., v[i]a[n]. We get len(v) arrays/lists, adding them together.
The result of np.convolve([1, 2, 3], [0, 1, 0.5]) is calculated as following:
step 1:
1, 2, 3
0, 1, 0.5
a=0, 0, 0,
step two:
1, 2, 3
0, 1, 0.5
b=0, 1, 2, 3,
step three:
1, 2, 3
0, 1, 0.5
c=0, 0, 0.5, 1, 1.5
finally, adding a, b, and c:
0, 0, 0,
+ 0, 1, 2, 3,
+ 0, 0, 0.5, 1, 1.5
-------------------
= 0, 1, 2.5, 4, 1.5
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | yann |
