0
arr = np.array([[1,2],
                [2,3],
                [5,6]])

Is there any numpy function to clone the above 2d array into 3d array as shown below? If not, how to do it with multiple steps?

bb = np.?????(arr, 3)
>> print(bb)

[[[1,2],
   [2,3],
   [5,6]],
 [[1,2],
  [2,3],
  [5,6]],
 [[1,2],
  [2,3],
  [5,6]]]
1

1 Answer 1

1

You can make your own custom function like this:

import numpy as np
arr = np.array([[1,2],
                [2,3],
                [5,6]])
def to_3d(arr, n): 
    l = (arr for _ in range(n))
    return np.array(list(l))
print (to_3d(arr, 3))

Output:

[[[1 2]
  [2 3]
  [5 6]]

 [[1 2]
  [2 3]
  [5 6]]

 [[1 2]
  [2 3]
  [5 6]]]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.