np.array(list(range(10))) array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
accetta anche l'input senza list(), con ugual risultato
np.array(range(10))
dtype keyword to explicitly set the data type of the resulting array
np.array([1, 2, 3, 4], dtype='float32')
array([1., 2., 3., 4.], dtype=float32)
np.array([range(i, i + 3) for i in [2, 4, 6]])
array([[2, 3, 4], [4, 5, 6], [6, 7, 8]])
Create a length-10 integer array filled with zeros
np.zeros(10, dtype=int)
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
np.full((3, 5), 3.14)
np.arange(5, 20, 2.5) min,max,step
np.linspace(0, 1, 5) min,max,quanti_nr
np.random.random(10) 10 nr tra 0 e 1
np.random.randint(0,100,10) 10 nr in [0,100)
np.random.random((4, 3)) nr_righe,nr_colonne
np.random.normal(0,1,(4, 3))
np.random.seed(0) # seed for reproducibility x1 = np.random.randint(10, size=6) # One-dimensional array x2 = np.random.randint(10, size=(3, 4)) # Two-dimensional array x3 = np.random.randint(10, size=(3, 4, 5)) # Three-dimensional array
x3 ndim: 3 x3 shape: (3, 4, 5) x3 size: 60
dtype: int32
itemsize: 4 bytes nbytes: 240 bytes
just as with Python lists:
a one-dimensional array, the ith value (counting from zero) can be accessed by specifying the desired index in square brackets.
To index from the end of the array, use negative indices (counting from -1)
In a mD-array, items can be accessed using a comma-separated tuple of indices
x3[0,0,0]
x3[2,3,4]
inserting a floating-point value to an integer array, the value will be silently truncated.
x[start:stop:step]
default: start=0, stop=size of dimension, step=1
The NumPy slicing syntax follows that of the standard Python list.
Multi-dimensional slices work in the same way, with multiple slices separated by commas.
Subarrays are views, not copies; instead in Python list, slices will be copies,
x2_sub_copy = x2[:2, :2].copy()
np.arange(1, 10).reshape((3, 3))
array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
to put the numbers 1 through 9 in a 3×3 grid
is common reshaping, can be done with the reshape method, or using of the newaxis keyword within a slice operation
x = np.array([1, 2, 3])
x.reshape((1, 3)) |
=
|
x[np.newaxis, :]) |
x.reshape((3, 1)) |
= |
x[:, np.newaxis] |
Automatic differentiation, differenziazione automatica, algoritmica.
http://www.taigtools.com/cmill.html
from http://www.lfd.uci.edu/tour/
from Unofficial Windows Binaries for Python Extension Packages
from http://packages.python.org/uncertainties/
from http://wiki.python.org/moin/NumericAndScientific
The point of having nice syntax is to minimize the line-noise and mental overhead of mapping the mental idea to working code
ref: technicaldiscovery.blogspot by Travis Oliphant