maybe this is a easy question, but is there a fast way to duplicate elements in a array? It should work like this way for 3D:
1 2 3
4 5 6
7 8 9
1 1 2 2 3 3
1 1 2 2 3 3
4 4 5 5 6 6
4 4 5 5 6 6
7 7 8 8 9 9
7 7 8 8 9 9
I tried it with 3 nested for-loops, but this was really slow.
Use numpy. copy() function to copy Python NumPy array (ndarray) to another array. This method takes the array you wanted to copy as an argument and returns an array copy of the given object. The copy owns the data and any changes made to the copy will not affect the original array.
NumPy: repeat() function The repeat() function is used to repeat elements of an array. Input array. The number of repetitions for each element. repeats is broadcasted to fit the shape of the given axis.
The np. repeat function repeats the individual elements of an input array. But np. tile will take the entire array – including the order of the individual elements – and copy it in a particular direction.
>>> a = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
>>> np.repeat(np.repeat(a, 2, 0), 2, 1)
array([[1, 1, 2, 2, 3, 3],
[1, 1, 2, 2, 3, 3],
[4, 4, 5, 5, 6, 6],
[4, 4, 5, 5, 6, 6],
[7, 7, 8, 8, 9, 9],
[7, 7, 8, 8, 9, 9]])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With