I have an array:
x = np.array([[1, 2, 3], [4, 5, 6]])
and I want to create another array of shape=(1, 1)
and dtype=np.object
whose only element is x.
I've tried this code:
a = np.array([[x]], dtype=np.object)
but it produces an array of shape (1, 1, 2, 3)
.
Of course I can do:
a = np.zeros(shape=(1, 1), dtype=np.object)
a[0, 0] = x
but I want the solution to be easily scalable to greater a
shapes, like:
[[x, x], [x, x]]
without having to run for
loops over all the indices.
Any suggestions how this could be achieved?
UPD1
The arrays may be different, as in:
x = np.array([[1, 2, 3], [4, 5, 6]])
y = np.array([[7, 8, 9], [0, 1, 2]])
u = np.array([[3, 4, 5], [6, 7, 8]])
v = np.array([[9, 0, 1], [2, 3, 4]])
[[x, y], [u, v]]
They may also be of different shapes, but for that case a simple np.array([[x, y], [u, v]])
constructor works fine
UPD2
I really want a solution that works with arbitrary x, y, u, v
shapes, not necessarily all the same.
See Question&Answers more detail:
os