I have 2 arrays, one of shape (455,98) and a second with shape (182,472). A geometric description is as per the attached image. Is there a pythonic way to do this? I would also be happy to receive guidance on how to write a function to achieve this.
Advertisement
Answer
Don’t know if I understood your question completely. However this code will add the numbers from a
and b
arrays within the intersection.
JavaScript
x
10
10
1
import numpy as np
2
3
a = np.ones((455,98))
4
b = np.ones((182,472))
5
6
c = a[:b.shape[0], :a.shape[1]] + b[:b.shape[0], :a.shape[1]]
7
8
print(c)
9
print(c.shape)
10
Could alternatively use something like:
JavaScript
1
2
1
c = np.dstack((a[:b.shape[0], :a.shape[1]], b[:b.shape[0], :a.shape[1]]))
2
To retrieve both elements from each array.