Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

copy array along axis numpy

a = np.array([[1, 2], [1, 2]])

# indexing with np.newaxis inserts a new 3rd dimension, which we then repeat the
# array along, (you can achieve the same effect by indexing with None, see below)
b = np.repeat(a[:, :, np.newaxis], 3, axis=2)

print(b[:, :, 2])
# [[1 2]
#  [1 2]]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #copy #array #axis #numpy
ADD COMMENT
Topic
Name
6+6 =