Reputation: 8203
I would like stack together arrays that have different, but broadcast compatible arrays. Given 7x5, 7x1, 1x5 and 1x1 arrays I want to do something like
a475 = mkarr([a75, a71, a15, a11])
where a455
will be a 4x7x5 array.
Ideally I would also like to be able to do
a2275 = mkarr([[a75, a71], [a15, a11]])
to get a 2x2x7x5 array.
What is the most concise way to express these operation in numpy?
Upvotes: 1
Views: 159
Reputation: 59731
You can use np.broadcast_arrays
:
a475 = np.stack(np.broadcast_arrays(a75, a71, a15, a11))
Note that this creates views of the original arrays, so it should not entail any extra memory usage.
Upvotes: 3