Representing Data with NumPy
Understand how to use NumPy arrays to represent data efficiently in Python. Learn to create, index, and slice arrays, and perform scalar and element-wise arithmetic operations. This lesson helps you apply NumPy functions to manipulate multi-dimensional data and solve coding challenges.
Introduction to NumPy
Sometimes, we need a data structure called arrays to represent a group of the same data type together. For this purpose, in Python, we can either use a list or use NumPy arrays. NumPy is a library for the Python programming language that adds support for large, multi-dimensional arrays and matrices, along with an extensive collection of high-level mathematical functions to operate on these arrays. To use NumPy, you will need to import it, as shown in the code snippet below.
NumPy arrays
You can create an uninitialized array using the empty(shape, type) function. Alternatively, you can create an array of zeros or ones by using the zeros(shape, type) or ones(shape, type) function, respectively.
For creating a one-dimensional array, the argument shape has to be equal to the length of the array.
For creating a two-dimensional or an N-dimensional array, the argument shape ...