3-dimensional array in numpy

New at Python and Numpy, trying to create 3-dimensional arrays. My problem is that the order of the dimensions are off compared to Matlab. In fact the order doesn’t make sense at all.

Creating a matrix:

x = np.zeros((2,3,4))

In my world this should result in 2 rows, 3 columns and 4 depth dimensions and it should be presented as:

[0 0 0      [0 0 0      [0 0 0      [0 0 0
 0 0 0]      0 0 0]      0 0 0]      0 0 0] 

Seperating on each depth dimensions. Instead it is presented as

[0 0 0 0      [0 0 0 0
 0 0 0 0       0 0 0 0
 0 0 0 0]      0 0 0 0]

That is, 3 rows, 4 column and 2 depth dimensions. That is, the first dimension is the “depth”. To further add to this problem, importing an image with OpenCV the color dimension is the last dimension, that is, I see the color information as the depth dimension. This complicates things greatly if all I want to do is try something on a known smaller 3-dimensional array.

Have I misunderstood something? If not, why the heck is numpy using such a unintuitive way of working with 3D-dimensional arrays?

Leave a Comment