Answers for "repeat array along new axis"

0

repeat array along new axis

a = np.array([[1, 2], [1, 2]])
# indexing with np.newaxis inserts a new 3rd dimension, 
# which we then repeat the array along
b = np.repeat(a[:, :, np.newaxis], 3, axis=2)
print(b.shape)
# (2, 2, 3)
Posted by: Guest on August-13-2021

Python Answers by Framework

Browse Popular Code Answers by Language