What is np.array() in Python

The Numpy array object in Numpy is called ndarray. We can create ndarray using numpy.array() function. It is used to convert a list, tuple, etc. into a Numpy array.

Syntax: numpy.array(object, dtype=None)

Creating a NumPy array using the .array() function.

Python3




# importing numpy module
import numpy as np
 
# creating numpy array
res = np.array(['G', 'F', 'G'])
 
print("Numpy Array in python :", res)
print(type(res))


Output:

Numpy Array in python : ['G' 'F' 'G']
<class 'numpy.ndarray'>

Difference between Numpy array and Numpy matrix

While working with Python many times we come across the question that what exactly is the difference between a numpy array and numpy matrix, in this article we are going to read about the same.

Similar Reads

What is np.array() in Python

The Numpy array object in Numpy is called ndarray. We can create ndarray using numpy.array() function. It is used to convert a list, tuple, etc. into a Numpy array....

What is numpy.matrix() in Python

...

Difference between Numpy array and Numpy Matrix

A matrix in Numpy returns a matrix from a string of data or array-like object. The matrix obtained is a specialized 2D array....

Table of Differences between the Numpy Array and Numpy Matrix

...

Contact Us