-2

How can i say shape of a n-dimension matrix in numpy for example

import numpy as np
a=np.array([[[1,2],[3,4]]])
print(a.shape)

output of these is (1,2,2) How can i say it without using a computer. Thanks for any help.

greg-449
  • 109,219
  • 232
  • 102
  • 145
Sandeep
  • 3
  • 3

1 Answers1

1

You have 3 opening brackets at the beginning, so the shape has 3 elements.

The first shape element is 1, because the first opening bracket contains one element, ie. "[[1,2],[3,4]]".

The second shape element is 2, because you have two elements on that level, "[1,2]" and "[3,4]".

The third shape element is 2, because again you have two elements on that level "1" and "2" (as well as "3" and "4").

micha137
  • 1,195
  • 8
  • 22