NumPy is the fundamental general-purpose array_processing package for scientific computing with Python
designed to efficiently manipulate large multi-dimensional arrays of arbitrary records
without sacrificing too much speed for small multi-dimensional arrays.
NumPy is built on the Numeric code base and adds features introduced by numarray
as well as an extended C-API and the ability to create arrays of arbitrary type
which also makes NumPy suitable for interfacing with general-purpose data-base applications.
To download NumPy wheels, go to the URL:
https://pypi.python.org/pypi/numpy
To install NumPy 1.13.1
>>
pip install numpy-1.13.1-cp36-none-win32.whl
Examples:
import numpy as np
>>> np
<module 'numpy' from 'F:\\Python\\Python36-32\\lib\\site-packages\\numpy\\__init__.py'>
>>> x = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
>>> x
array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
>>> x = x**2
>>> x
array([ 1, 4, 9, 16, 25, 36, 49, 64, 81, 100], dtype=int32)
>>> y = np.arange(1,21,2)
>>> y
array([ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19])
>>> type(x),type(y)
(<class 'numpy.ndarray'>, <class 'numpy.ndarray'>)
##########################################################
# Return Pearson product-moment correlation coefficients.
##########################################################
>>> print(np.corrcoef(x,y))
[[ 1. 0.97455863]
[ 0.97455863 1. ]]
>>> z = x + y
>>> z
array([ 2, 7, 14, 23, 34, 47, 62, 79, 98, 119])
#####################################################################################
# Take a sequence of 1-D arrays and stack them as columns to make a single 2-D array
#####################################################################################
>>> np.column_stack((x,y))
array([[ 1, 1],
[ 4, 3],
[ 9, 5],
[ 16, 7],
[ 25, 9],
[ 36, 11],
[ 49, 13],
[ 64, 15],
[ 81, 17],
[100, 19]])
##################################
# To solve the math equations:
# 6x + 2y = 18 , 2x + 4y = 16
##################################
>>> a = np.array([[6,2],[2,4]])
>>> a
array([[6, 2],
[2, 4]])
>>> b = np.array([18,16])
>>> b
array([18, 16])
>>> c = np.linalg.solve(a,b)
>>> c
array([ 2., 3.])
>>>
######################################
# Check the correctness of the answer
######################################
>>> np.allclose(np.dot(a,c),b)
True
Thus,
x = 2, y = 3
#####################################################
# To generate 10 random integers between 1 and 100
#####################################################
>>> rand_array = np.random.randint(1,100,10)
>>> rand_array
array([48, 99, 53, 26, 68, 69, 24, 46, 85, 3])
############################################################
# Gives a new shape to an array without changing its data
############################################################
>>> x1 = np.arange(6).reshape((3,2))
>>> x1
array([[0, 1],
[2, 3],
[4, 5]])
#########################
# Reverse the dimensions
#########################
>>> np.transpose(x1)
array([[0, 2, 4],
[1, 3, 5]])
[Reference]
1. http://www.numpy.org/
2. https://pypi.python.org/pypi/numpy
3. https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.arange.html
4. https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.linalg.solve.html
5. https://docs.scipy.org/doc/numpy-1.13.0/reference/routines.random.html
6. https://docs.scipy.org/doc/numpy/reference/generated/numpy.transpose.html
7. https://zh.wikipedia.org/wiki/NumPy
