1

Let's say I have an array like

0,1,0
0,1,0
0,1,0

Is there a way that I can get this array to be double the dimensions so that let's so the new array is like this:

0,0,1,1,0,0
0,0,1,1,0,0
0,0,1,1,0,0
0,0,1,1,0,0
0,0,1,1,0,0
0,0,1,1,0,0

5
  • Could you rephrase your question? What is the original dimensions of your array and the final dimension you need? Commented Jun 19, 2021 at 22:23
  • also, can't you just use numpy.resize? Commented Jun 19, 2021 at 22:25
  • You want every row to be duplicated so [a, b, c] would become [a, a, b, b, c, c], and every column to then be duplicated as well? Commented Jun 19, 2021 at 23:03
  • @AryanBansal numpy.resize would take array [a, b, c] and produce [a, b, c, a, b, c] Commented Jun 19, 2021 at 23:10
  • @Jared the question was edited after my comment. Earlier it was a lot more confusing and unclear so I wasn't sure what OP wanted to do. Commented Jun 20, 2021 at 6:19

1 Answer 1

2

numpy.repeat() should work here. I think you have to call it twice to get it to repeat in both axes.

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

a.repeat(2, axis=1).repeat(2, axis=0)

This gives you:

array([[0, 0, 1, 1, 0, 0],
       [0, 0, 1, 1, 0, 0],
       [0, 0, 1, 1, 0, 0],
       [0, 0, 1, 1, 0, 0],
       [0, 0, 1, 1, 0, 0],
       [0, 0, 1, 1, 0, 0]])
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.