Home > Back-end >  i write 3d matrix . but why it is showed it is 2d
i write 3d matrix . but why it is showed it is 2d

Time:05-30

i write a 3 dimension matrix. i used .ndim to get the dimension. but it shows it is 2D

third_matrix = np.array([[23,45,56,78],[98,76,54,43],[80,79,57,35]])
print("third matrix dimension = ",third_matrix.ndim)

output is :

third matrix dimension = 2

CodePudding user response:

You have a list of lists, so it is a 2D matrix. In order to make it 3D, put the numbers in lists.

i.e

[ [[23],[45],[56],[78]],  [[98],[76],[54],[43]],  [[80],[79],[57],[35]] ]

CodePudding user response:

You also have to have in Mind, that numpy.array() only accepts an iterable as input, not many, maybe the confusion is there.

2_D_list = [[23,45,56,78],
[98,76,54,43],
[80,79,57,35]]
numpy.array(2_D_list)

The output is exactly the same. Its a 2D list. THere are 3 elements in the parent list, and each of those has 4 Ints.

CodePudding user response:

These are the dimensions

1_dimension = [4, 9, 4, 5]
2_dimension = [[23,45,56,78],[98,76,54,43],[80,79,57,35]]
3_dimension = [[[23],[45],[56],[78]], [[98],[76],[54],[43]], [[80],[79],[57],[35]]]
  • Related