NumPy Basics - Creating NumPy Arrays and Array Attributes
We'll cover the following
1. Creating Arrays
There are two ways to create arrays in NumPy:
a. Arrays From Lists
The first step when working with packages is to define the right “imports”. We can import NumPy like so:
import numpy as np
Notice that np is the standard shorthand for NumPy.
There are multiple ways to create arrays. Let’s start by creating an array from a list using the np.array
function.
We can create a one-dimensional (1D) array from a list by passing the list as input parameters to the np.array function:
np.array([1, 2, 3, 4])
Get hands-on with 1200+ tech skills courses.