What is the numpy.array() function in Python?

Overview

The numpy.array() function is used to create an arrayAn array is a collection of multiple items of the same data type stored in a single variable..

Syntax

numpy.array(object, dtype=None, ndmin=0, like=None)

Parameters

The numpy.array() function takes the following parameter values:

  • object: This represents the array_like object.
  • dtype: This represents the desired data type of the array to be created. This is optional.
  • ndim: This represents the minimum dimension of the desired array. This is optional.

Return value

The numpy.array() function returns an array object with the specified parameters.

Example

import numpy as np
# implementing the numpy.array() function
myarray = np.array([1, 2, 3, 4, 5,], dtype = complex, ndmin= 2)
print(myarray)

Explanation

  • Line 1: We import the numpy module.
  • Line 4: Using the numpy.array() function, we create an array with complex data types that have at least 2 dimensional values. The output is assigned to another variable, myarray.
  • Line 6: We print the variable myarray.

Free Resources