Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

numpy
python
functions
communitycreator

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

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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)
Implementing the numpy.array() function

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.

RELATED TAGS

numpy
python
functions
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring