The power of Numpy package is the multidimentional array with ease of working with the array elements. There are different ways to create multidimentional array in Numpy and here we show some. See also how to create Numpy Array and Matrix and how to check the attributes of objects in Numpy in the last two blogposts.

A one dimentional array is created by using the following command:

To see the array on the display, we use the print statement:

To know the dimension of the dimension of the array we use the ndim attribute.

Now to create two dimensional array we use the following command.

And print out the array:

To know the dimension we use the ndim attribute as follows:

In the above array creation we used the arange( ) function. But we can also put our own desired array elements as follows:

So in this way you create multi-dimensional array in Numpy.

A one dimentional array is created by using the following command:

import numpy as np A1 = np.array([1,2,3])

To see the array on the display, we use the print statement:

`print(A1)`

[1 2 3]

To know the dimension of the dimension of the array we use the ndim attribute.

`print(A1.ndim)`

1

Now to create two dimensional array we use the following command.

B1 = np.array([np.arange(2), np.arange(2)])

And print out the array:

`print(B1)`

[[0 1] [0 1]]

To know the dimension we use the ndim attribute as follows:

`print(B1.ndim)`

2

In the above array creation we used the arange( ) function. But we can also put our own desired array elements as follows:

C1 = np.array([[1,2,3],[4,5,6]]) print(C1)

[[1 2 3] [4 5 6]]

So in this way you create multi-dimensional array in Numpy.

## 0 comments:

## Post a Comment