Data Science Academy — NumPy Operations

Roman Ceresnak, PhD
2 min readFeb 8, 2022

--

Photo by Andrea Piacquadio from Pexels

In this section, I want to focus on NumPy Operations. Please open your Jupyter notebook and let’s jump to it.

Arithmetic Operation

Let’s import NumPy library

import numpy as np

Let’s create a simple array list with values from 0 to 10

array = numpy.arange(0,10)

Let’s see the result

output => array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

Let’s play around with simple arithmetic operations:

array + array

output => array([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18])
array * array

output => array([ 0, 1, 4, 9, 16, 25, 36, 49, 64, 81])
array - array

output => array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

Universal Array Functions

NumPy accompanies numerous general exhibit capacities, which are basically numerical tasks you can use to play out the activity across the cluster. Let’s see:

First of all let’s reset our array variable:

array = numpy.arange(0,10)

Let’s taking Square Roots:
np.sqrt(array)

output => array([ 0. , 1. , 1.41421356, 1.73205081, 2. ,
2.23606798, 2.44948974, 2.64575131, 2.82842712, 3. ])

Let’s calculate exponential (e^):
numpy.exp(array)

output => array([ 1.00000000e+00, 2.71828183e+00, 7.38905610e+00,
2.00855369e+01, 5.45981500e+01, 1.48413159e+02,
4.03428793e+02, 1.09663316e+03, 2.98095799e+03,
8.10308393e+03])

How to get the highest value from the array? This way:

numpy.max(array)

output => 9

--

--

Roman Ceresnak, PhD
Roman Ceresnak, PhD

Written by Roman Ceresnak, PhD

AWS Cloud Architect. I write about education, fitness and programming. My website is pickupcloud.io

No responses yet