Array 1: [1 2 3] Shape of Array 1: (3,) Array 2: [[1 2 3] [4 5 6]] Shape of Array 2: (2, 3) Array 3: [[1 2 3]] Shape of Array 3: (1, 3)
The output of numpy.ndarray.shape shows the lengths of the corresponding array dimensions. For example,
array1: [1 2 3]
So, the shape of array1 is (3,). It means array1 is a one-dimensional array and the length of the corresponding array’s dimension is 3. In other words, array1 has three elements along its dimension.
Similarly,
Array 2: [[1 2 3] [4 5 6]] Shape of Array 2: (2, 3)
It means array2 is 2-dimensional. And it has 2 rows and 3 columns.
And,
Array 3: [[1 2 3]] Shape of Array 3: (1, 3)
It means that array3 is 2-dimensional. And it has one row and three columns.
So, if the array is [[[1, 2], [3, 4]], [[5, 6], [7, 8]]], the shape of the array will be (2, 2, 2). It means the array is 3-dimensional. And it has 2 elements along every dimension.







































0 Comments