Introduction to NumPy_ Learn NumPy_ Introduction Cheatsheet _ Codecademy
Introduction to NumPy_ Learn NumPy_ Introduction Cheatsheet _ Codecademy
NumPy Arrays
NumPy (short for “Numerical Python”) is a Python # Import the NumPy module, aliased as
module used for numerical computing, creating arrays
'np'
and matrices, and performing very fast operations on
those data structures. The core of NumPy is a import numpy as np
multidimensional Array object.
The NumPy .array() method is used to create
# NumPy Arrays can be created with a list
new NumPy Arrays.
my_array = np.array([1, 2, 3, 4])
Accessing NumPy Array elements by index
Individual NumPy Array elements can be accessed by matrix = np.array([[1, 2, 3],
index, using syntax identical to Python lists:
[4, 5, 6],
array[index] for a single element, or
array[start:end] for a slice, where start [7, 8, 9]])
and end are the starting and ending indexes for the
slice. print(matrix[0, 0])
Nested Arrays or elements can be accessed by adding
# 1
additional comma-separated parameters.
print(matrix[1,:])
# array([4, 5, 6])
Print Share