Installing and using NumPy in Python

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
No comments yet. Be the first to comment.
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

First of all, let me explain a bit what NumPy is and why you might need it. NumPy is a Python library that is used for working with arrays. It stands short for Numeric Python
This, of course, is still a bit vague. In general, it makes working with arrays (lists) about 50x faster than traditional python lists.
To install NumPy, we must run a pip install command for it.
pip install numpy
Then we have to import it into our Python file.
import numpy
Now we can convert a list into a numpy array:
arr = numpy.array([1, 2, 3, 4, 5])
print(arr)
However, it's quite often used to have the numpy imported as the np alias.
We can do so like this:
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print(arr)
This now does the exact same thing, but it's easier to write.
If you ever wonder what version of numpy you have installed, you can simply print that out.
print(np.__version__)
# 1.20.3
The cool part about the NumPy arrays is that they can be built from all array-like data types of Python.
Which include the list, tuple, dictionary.
tuple = np.array((1, 2, 3, 4, 5))
print(tuple)
list = np.array(["dog", "cat", "penguin"])
print(list)
set = np.array({"dog", "cat", "penguin"})
print(set)
It's super easy to convert this stuff to NumPy arrays since we can eventually do more stuff and faster!
In a follow-up article, I'll go more in-depth about the options for the NumPy arrays.
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter