Declare NumPy Array
Declare NumPy Array
Let’s learn how to declare a NumPy Array in this tutorial. NumPy can define multi-dimensional arrays using the np.array() function.
Declare NumPy Array
Let’s first learn how to declare one-dimensional arrays. A one-dimensional NumPy array is like a list of numbers. The dimensions of a NumPy array are stored in an attribute called shape.
We can specify the data type of the array using the dtype parameter.
The shape of an array refers to its dimensions. We can use the shape attribute to determine the dimensions of a NumPy array. We can also change the shape of an array using the reshape() method.
Example
# Declare Python NumPy Array
# Python Tutorials – www.TestingDocs.com
# Import NumPy
import numpy as np
# Declare NumPy 1-D Array
arr = np.array([12.5,85.3,96.7,93.5], dtype = ‘float64’)
# Print array
print(arr)
# Print dimension
print(arr.shape)
# Print array element
print(arr[1])
—
Python Tutorials
Python Tutorial on this website can be found at:
https://www.testingdocs.com/python-tutorials/
More information on Python is available at the official website: