Python NumPy Array – Create NumPy Ndarray (Multidimensional Array)
What is the NumPy array?
Python NumPy array is a collection of a homogeneous data type. It is most similar to the python list. You can insert different types of data in it. Like integer, floating, list, tuple, string, etc.
To create a multidimensional array and perform a mathematical operation python NumPy ndarray is the best choice. The ndarray stands for N-Dimensional arrays.
Fig 1.1 Representation of NumPy ndarray (multidimensional array )
Let’s jump on practical session NumPy
Create NumPy ndarray (1D array)
To create NumPy 1D array use array() function and give one argument of items of a list to it.
Syntax: array(object, dtype=None, copy=True, order=’K’, subok=False, ndmin=0)
1 2 3 |
|
1 |
|
In machine learning and data science NumPy 1D array known as vector. Specially use to store and perform an operation on target values.
Create NumPy ndarray (2D array)
To create NumPy 2D array use array() function and give one argument of items of lists of the list to it.
Syntax: array(object, dtype=None, copy=True, order=’K’, subok=False, ndmin=0)
1 2 3 |
|
1 2 3 4 5 |
|
In machine learning and data science NumPy 2D array known as a matrix. Specially use to store and perform an operation on input values.
Create NumPy ndarray (3D array)
To create NumPy 3D array use array() function and give one argument of items of lists of lists of the list to it.
Syntax: array(object, dtype=None, copy=True, order=’K’, subok=False, ndmin=0)
1 2 3 |
|
1 2 3 4 5 |
|
In machine learning and data science NumPy 3D array known as a tensor. Specially used to store and perform an operation on three-dimensional data like color image.
How to store different types of data in NumPy ndarray?
The array() function accepts different types of data. You can insert it while creating an array.
1 2 3 4 5 6 7 8 9 |
|
1 2 3 4 5 6 7 |
|
How to set default data type?
By default, The python NumPy array data type is none. To set it, give an argument to array() function as the desired data type. like int, float, str, etc.
1 2 3 |
|
1 |
|
Generally, remaining default argument of array () function never use but you can try it. In this way, you can create a NumPy multidimensional arrays.
Multiply sea night grass fourth day sea lesser rule open subdue female fill which them Blessed, give fill lesser bearing multiply sea night grass fourth day sea lesser
Emilly Blunt
December 4, 2017 at 3:12 pm