0

I have a ndarray(example given below).

A=
[[0.1  1.1 ]
 [0.1  1.3 ]
 [0.25 1.25]
 [0.25 1.45]
 [0.37 1.37]
 [0.35 1.8 ]]

I want to reshape it as

B=
[[[0.1  1.1 ] [0.1  1.3 ]]
 [[0.25  1.25 ] [0.25  1.45 ]]
 [[0.37  1.37 ] [0.35  1.38 ]]]

so that doing

B[0] gives me [[0.1  1.1 ] [0.1  1.3 ]] and B[0][0] gives [0.1  1.1 ]
tanay
  • 468
  • 5
  • 16
  • What is the issue, exactly? Have you tried anything, done any research? **Stack Overflow is not a free code writing service.** See: [tour], [ask], [help/on-topic], https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users. – AMC Feb 26 '20 at 19:48
  • @AMC I know it's not a free code writing service. The issue is I am not so familiar with the reshape function so I was not able to get the correct output. From next time I will make sure that I will also post what I did.. – tanay Feb 26 '20 at 20:12
  • This is a duplicate of https://stackoverflow.com/questions/14476415/reshape-an-array-in-numpy, by the way. – AMC Feb 26 '20 at 20:14

2 Answers2

1

Use standard numpy reshaping:

B = A.reshape(-1, 2, 2)
Jan Christoph Terasa
  • 5,781
  • 24
  • 34
1

The following should work

A.reshape(3,2,2)
Nik P
  • 224
  • 1
  • 5