User Tools

Site Tools


appunti3s:numpy

This is an old revision of the document!


indice < linguaggio_python

numpy

https://numpy.org/doc/stable/

Il python (classico) dispone di oggetti array.array (monodimensionali)

numpy permette di usare un nuovo tipo di array

 numpy.ndarray 

noti anche con il termine “array” (cosa che potrebbe causare confusione se non si usasse il nome del modulo numpy come prefisso)

Vediamo alcuni esempi per definire un array
1.py
import numpy as np
a = [[ 1., 0., 0.], [ 0., 1., 2.]]
b = np.array([1.2, 3.5, 5.1])
c = np.array( [ [1.0,2.0], [3.0,4.0] ], dtype=complex )
d = np.zeros((3, 4))
e = np.ones((3, 4))
Esempio in cui si vuole valutare una funzione
2.py
from numpy import pi
x = np.linspace( 0, 2*pi, 100 )        # useful to evaluate function at lots of points
f = np.sin(x)
appunti3s/numpy.1594245896.txt.gz · Last modified: 2020/07/09 00:04 by profpro