https://docs.scipy.org/doc/numpy-dev/, https://www.python-course.eu/numpy.php/
NumPy is an acronym for "Numeric Python" or "Numerical Python" A python package that supports the creation and manipulation of n-dimensional arrays (ndarray) of homogeneous data types. Numpy objects are fixed at creation, adjusting the size creates a new object. The objects in the array must all have the same type ( You can defeat this somewhat in that if you create numbpy array of lists, the lists themselves can contain different objects)
This means that mathematical operations can happen quickly since the size and type of the array elements are fixed. Numbpy was designed for using large arrays and matrices. SciPy (Scientific Python) extends the use of the numby ndarray's with advanced fucntions: minimization, regression, Fourier-transformation, ...
If you already have python and pip installed the use:
pip install numpy scipy
Or follow the intstructions from http://www.numpy.org/ or https://docs.scipy.org/doc/numpy-dev/user/index.html#user
Import it to use it
In [1]:
#import numbpy
import numpy as np
# One dimensional array
cvalues = [25.3, 24.8, 26.9, 23.9]
c=np.array(cvalues)
print (c)
In [6]:
# Assume they are celsius measurements that we want to convert to Fahrenheit
# List expression evaluation
print "list expression result="+str([ x*9/5+32 for x in cvalues] )
print "numbpy broadcast result="+str(c*9/5+32) # simpler syntax
Python ranges range([start], stop[, step]) vs xrange Renames xrange() to range() and wraps existing range() calls with list
np.arange([start,] stop[, step,], dtype=None) the stop value is not include in the numbers returned. Default step is one, the dtype is based on the start number format unless specified in dtype.
In [12]:
range(1,15,2) # operates on integers only
Out[12]:
In [ ]:
In [8]:
np.arange(-1.5,15,3.1415) # can create any sequence of numbers
Out[8]:
In [25]:
np.arange((1.0-2.5j),50,(1-4j)) #Even complex number sequences
Out[25]:
https://docs.scipy.org/doc/numpy-dev/reference/index.html#reference
Array objects
a. N-dimensional array https://docs.scipy.org/doc/numpy-dev/reference/arrays.ndarray.html
b. scalars https://docs.scipy.org/doc/numpy-dev/reference/arrays.scalars.html
c. indexing https://docs.scipy.org/doc/numpy-dev/reference/arrays.indexing.html
d. interating over arrays https://docs.scipy.org/doc/numpy-dev/reference/arrays.nditer.html
e. Standard array subclasses https://docs.scipy.org/doc/numpy-dev/reference/arrays.classes.html
f. the array interface https://docs.scipy.org/doc/numpy-dev/reference/arrays.interface.html
g. datetimes and timedeltas https://docs.scipy.org/doc/numpy-dev/reference/arrays.datetime.html
In [ ]: