<jupyter_start><jupyter_text>Numpy---Numerical Processing library> NumPy (pronounced "Numb Pie" or sometimes "Numb pee") is an extension to the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large library of high-level mathematical functions to operate on these arrays. - Wikipedia What is Numpy ?[http://www.numpy.org/](http://www.numpy.org/)[Reference](https://docs.scipy.org/doc/numpy/reference/)- Numpy "numeric processing library"<jupyter_code>import numpy as np
np.__version__<jupyter_output><empty_output><jupyter_text>1-Dimensional Arrays Create a new array<jupyter_code>arr = np.array([1, 2, 3])
arr<jupyter_output><empty_output><jupyter_text>*Array are not actually matrix but can be considered as such, as most of array operations relates to matrix operations*$$\begin{bmatrix}    1 & 2 & 3\end{bmatrix}$$<jupyter_code>type(arr)<jupyter_output><empty_output><jupyter_text>*ndarray: n-dimensional array*  Properties (Attributes) of an array<jupyter_code>arr.dtype<jupyter_output><empty_output><jupyter_text>> This means that all the elements are of type integer of 64 bit.*Note: Numpy array elements are of single types unlike of multitype of list*<jupyter_code>arr.shape<jupyter_output><empty_output><jupyter_text>*1-dimensional array with 3 elements*<jupyter_code>arr.ndim<jupyter_output><empty_output><jupyter_text>*dimension of the array*<jupyter_code>arr.size<jupyter_output><empty_output><jupyter_text>*number of items in an array*<jupyter_code>arr.itemsize<jupyter_output><empty_output><jupyter_text>*size of each item in bytes*<jupyter_code>arr.nbytes<jupyter_output><empty_output><jupyter_text>*size of array in bytes*<jupyter_code>arr.itemsize * arr.size == arr.nbytes<jupyter_output><empty_output><jupyter_text>2-Dimensional Array<jupyter_code>arr2 = np.array([[1, 2, 3], [4, 5, 6]])
arr2
arr2.ndim
arr2.shape
arr2.size<jupyter_output><empty_output><jupyter_text>3-Dimensional Array<jupyter_code>arr3 = np.array([[[1, 2, 3], [1, 2, 3]], [[1, 2, 3], [1, 2, 3]]])
arr3
arr3.ndim
arr3.shape
arr3.size<jupyter_output><empty_output><jupyter_text>Arrays generate an array of 10 random numbers<jupyter_code>np.random.randn(10)<jupyter_output><empty_output><jupyter_text>generate an array of 10 random numbers between 0 and 1<jupyter_code>np.random.rand(10)<jupyter_output><empty_output><jupyter_text>generate an array of 10 random integers between 1 and 10<jupyter_code>np.random.randint(1, 10, size=10)<jupyter_output><empty_output><jupyter_text>generate an array of range from 1 to 10<jupyter_code>np.arange(1, 10)<jupyter_output><empty_output><jupyter_text>array from 1 to 10 with every second element in range<jupyter_code>np.arange(1, 10, 2)<jupyter_output><empty_output><jupyter_text>generate an array of 10 linearly spaced values from 0 to 1<jupyter_code>np.linspace(0, 1, num=10)<jupyter_output><empty_output><jupyter_text>array of length 10 with values as zero<jupyter_code>np.zeros(10)<jupyter_output><empty_output><jupyter_text>array of length 10 with values as one<jupyter_code>np.ones(10)<jupyter_output><empty_output><jupyter_text>empty array of length 10<jupyter_code>np.empty(10)<jupyter_output><empty_output><jupyter_text>array of float<jupyter_code>arf = np.ones(5)
arf.dtype<jupyter_output><empty_output><jupyter_text>array of strings or unicode values<jupyter_code>aru = np.array(['1', 3, 5.6])
aru
aru.dtype<jupyter_output><empty_output><jupyter_text>Constants and Random values<jupyter_code>np.pi
np.inf
np.nan
np.NaN
np.random.randint(10)<jupyter_output><empty_output><jupyter_text>Numpy Functions<jupyter_code>np.sin(np.pi)
np.cos(34)
np.tan(45)
arr
np.sin(arr)
np.mean(arr)
np.median(arr)
np.abs(-10)
np.arcsin(0.5)
np.sum(arr)
np.cumsum(arr)
np.cumprod(arr)
np.prod(arr)
np.std(arr)
np.var(arr)
np.min(arr)
np.max(arr)<jupyter_output><empty_output><jupyter_text>Array as matrix<jupyter_code>np.eye(3)
np.diag((1, 4, 7))
np.ones((2, 3))
np.zeros((3, 2))<jupyter_output><empty_output><jupyter_text>Matplotlib<jupyter_code>import matplotlib
matplotlib.__version__
import matplotlib.pyplot as plt
plt.plot(np.arange(1, 30))
y = np.linspace(1, 10, num=100)
plt.plot(y)
y = np.random.rand(100)
plt.plot(y)
y = np.random.rand(100)
plt.scatter(np.arange(0, len(y)), y)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13053613053613053, 'fraction_numerical': 0.031002331002331, 'mean_word_length': 8.621076233183857, 'pattern_counts': {'":': 0, '<': 109, '<?xml version=': 0, '>': 111, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '27', 'dir': 'jupyter-structured-clean-dedup', 'id': '657857', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 1774, 'n_tokens_neox': 1661, 'n_words': 317, 'path': 'Sessions/Session-1.ipynb', 'repo_name': 'pywaker/datascience', 'size': '4290'}