Tutorial #1

BMI

Calcolo del Body Mass Index per 2 liste di pesi e altezze

import numpy as np

WEIGHT = [ 81.65, 97.52, 95.25, 92.98, 86.18, 88.45 ] # liste
HEIGHT = [  1.87,  1.87,  1.82,  1.91,  1.90,  1.85 ]

weight = np.array(WEIGHT) # numpy.ndarray
height = np.array(HEIGHT)
bmi    = weight/height**2

print(bmi)

Kg to pounds

import numpy as np

KG_LBS    = 2.20462262185
WEIGHT_KG = [ 100, 35, 40, 45, 50, 55, 60, 65 ]

np_weight_kg  = np.array(WEIGHT_KG)
np_weight_lbs = np_weight_kg*KG_LBS

print(np_weight_lbs)

Somma di vettori

Soluzione Python

x=[1, 2, 3, 4]
y=[4, 5, 6, 7]
z=[]

for i,j in zip(x,y):
z.append(i+j)
print(z)

Soluzione Numpy

import numpy as np

x=[1, 2, 3, 4]
y=[4, 5, 6, 7]

npx=np.array(x)
npy=np.array(y)
npz=np.add(npx, npy) # npz=npx+npy

print(npz)

Vedi: https://jobtensor.com/Tutorial/Python/en/NumPy