Numpy Introduction with Examples
If We Study Pandas, We Have to Study Numpy, Because Pandas Includes Numpy. Here, I’ll Introduce Numpy and Share Some Basic Functions. (This Tutorial Is Part of...
If we study Pandas, we have to study NumPy, because Pandas includes NumPy. Here, I’ll introduce NumPy and share some basic functions.
(This tutorial is part of our Pandas Guide. Use the right-hand menu to navigate.)
What is NumPy?
NumPy is a package that create arrays. It lets you make arrays of numbers with different precision and scale, plus string, so it is especially useful for scientific computing.
Python by itself only has floats, integers, and imaginary numbers. But NumPy expands what Python can do because it handles:
- 32-bit numbers
- 15 big numbers
- Signed numbers
- Unsigned numbers
- And more
But that’s not the only reason to use NumPy. It’s designed for efficiency and scale, making it the workhouse for large machine learning (ML) libraries like TensorFlow.
Now, let’s take a look at some basic functions of NumPy arrays.
Creating a NumPy array
Create an array with np.array(<array>).
Don’t put np.array(1,2,3,4,5) as 1,2,3,4,5 is not an array. NumPy would interpret the items after the commas as parameters to the array() function.
This creates an array:
import numpy as np arr = np.array([1,2,3]) arr
Results:
array([1,2,3])