Reputation: 1513
Lets say I make the following arrays:
>>> a = zeros((2,2,2))
>>> b = ones((2,2))
How can I insert b into the middle of a? So my resulting array will look like
array([[[ 0., 0.],
[ 0., 0.]],
[[ 1., 1.],
[ 1., 1.]],
[[ 0., 0.],
[ 0., 0.]]])
Upvotes: 2
Views: 5011
Reputation: 303
A way to show same as your result is using tuple
.
code:
b = numpy.ones((2,2))
a = numpy.zeros((2, 2))
tpl = a,
tpl = b,
tpl = a,
So you can consider it as 3dArray and also you can use for
loop to add multi array into it.Hope be helpfull.
Upvotes: 0
Reputation: 833
a=np.zeros((3,2,2))
b=np.ones((2,2))
a[1]=b*1
That will produce your output.
Upvotes: -1