DEV Community

Cover image for Numpy For Engineers, Scientists and Data Analysts
franklinobasy
franklinobasy

Posted on

Numpy For Engineers, Scientists and Data Analysts

A stackoverflow user asked this question:

If I have list=[1,2,3] and I want to add 1 to each element to get the output [2,3,4], how would I do that? I assume I would use a for loop but not sure exactly how.

Well, the answer to this question is to use Numpy

Numpy (Numerical Python) is a python package that comes with all the tools you will need for scientific computing. You should consider using numpy if you want to perform fast operations on arrays. These operations includes mathematical, logical, shape manipulation, sorting, selecting, basic linear algebra and statistical operations, discrete Fourier transform, the list goes on and on.

The code demonstration below addresses the question asked by the stackoverflow user above:

Input:

# import the numpy library
import numpy as np

# create the list, the convert the list to a numpy array
a = [1, 2, 3]
a = np.array(a)

# perform scalar addition on the array
b = a + 1
print(b) 

Enter fullscreen mode Exit fullscreen mode

if you type and test the code above correctly; your result should look like this:

Output

array([2, 3, 4])
Enter fullscreen mode Exit fullscreen mode

That was quite easy right? :-).

If you are new to python and you don't know how to write and execute the code above, the next few sentences are for you.

I use Anaconda and Jupyter notebook to write and run my python codes.

What is Anaconda Navigator

Anaconda Navigator is a desktop graphical user interface (GUI) included in Anaconda® distribution that allows you to launch applications and easily manage conda packages, environments, and channels without using command-line commands. Navigator can search for packages on Anaconda.org or in a local Anaconda Repository. It is available for Windows, macOS, and Linux.

Watch the videos below to help you set up Anaconda on your device(s):

  1. Setup Anaconda

  2. Using Jupyter notebook

Stay tuned for my next post on the Numpy For Engineers, Scientists and Data Analysts Series.

Top comments (0)