0

I would like to do a transformation like dimshuffle in theano using numpy.

Example input:

np.array([[1, 0, 0], [1, 0, 0]])

Example output:

np.array([
    [[1, 0, 0], [1, 0, 0]],
    [[1, 0, 0], [1, 0, 0]],
    [[1, 0, 0], [1, 0, 0]]
])

1 Answer 1

1

I don't know what dimshuffle does, but the output can be produced with repeat

In [319]: np.repeat(np.array([[1, 0, 0], [1, 0, 0]])[None,:,:],3,axis=0)
Out[319]: 
array([[[1, 0, 0],
        [1, 0, 0]],

       [[1, 0, 0],
        [1, 0, 0]],

       [[1, 0, 0],
        [1, 0, 0]]])

The input is 2d (2,3), so I have to add an axis - output is (3,2,3). tile would work, so would indexing, or even:

A=np.array([[1, 0, 0], [1, 0, 0]])
np.array([A,A,A])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.