<jupyter_start><jupyter_text>numpy arrays examples<jupyter_code>import numpy as np<jupyter_output><empty_output><jupyter_text>Create N dimensional arrays: By literal - note that the number of opening squares equals the dimension<jupyter_code>a = np.array([[1,2,3],[4,5,6]])
a<jupyter_output><empty_output><jupyter_text>Create array filled with random values: __np.empty__ of type __np.int8__<jupyter_code>b = np.empty( (3,2), dtype=np.int8  )
b<jupyter_output><empty_output><jupyter_text>Create array by __np.arange()__ method (quite simmilar to python's __range()__)<jupyter_code>b = np.arange(0,21,2)
b<jupyter_output><empty_output><jupyter_text>Simple indexing<jupyter_code>a[1][2]<jupyter_output><empty_output><jupyter_text>Basic numpy properties and methods The number of axes (dimensions) of the array: __a.ndim__<jupyter_code>a = np.array([[1,2,3],[4,5,6]])
a.ndim<jupyter_output><empty_output><jupyter_text>Tuple of integers indicating the size of the array in each dimension: __ndarray.shape__<jupyter_code>a = np.array([[1,2,3],[4,5,6]])
a.shape
b = np.array([[1,2],[3,4],[5,6]])
b.shape<jupyter_output><empty_output><jupyter_text>Total number of elements of the array: __a.size__<jupyter_code>a = np.array([[1,2,3],[4,5,6]])
a.size<jupyter_output><empty_output><jupyter_text>The size in bytes of each element of the array: __a.itemsize__<jupyter_code>a = np.array([[1,2,3],[4,5,6]])
a.itemsize<jupyter_output><empty_output><jupyter_text>Array Manipulations  Flatten the array<jupyter_code>a = np.array([[1,2,3],[4,5,6]])
a.ravel()<jupyter_output><empty_output><jupyter_text>reshaping arrays: __np.reshape()__<jupyter_code>a = np.array([[1,2,3],[4,5,6]])
a.shape
a.reshape(3,2)
a.reshape(1,6)<jupyter_output><empty_output><jupyter_text>Arrays Algebra (Element Wise)<jupyter_code>a = np.array([[1,2,3],[4,5,6]])
b = np.array([[1,2,3],[4,5,6]])

a+b<jupyter_output><empty_output><jupyter_text>matrix product: __dot()__<jupyter_code>a = np.array([[1,2,3],[4,5,6]])
b = np.array([[1,2],[3,4],[5,6]])

a.dot(b)
b.dot(a)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup