Creating Arrays
Size can be the following : 1) one-dimensional (Array) : where size = k = (k) eg : np.zeros(2) , creates an array of 2 elements 2) two-dimensional (Matrix) : where size = (a,b) eg : np.zeros((2,3)) , creates a matrix of 2 rows and one column 3) n-dimensional : where size = (a,b,c....etc) > 2 eg : np.zeros((2,3,5)) , creates a 3 dimensional array |
Reading Array From Text File
Make sure that you are typing the right datatype of the text file or you will receive an error The fmt keyword is used to specify the spacing in our text file where : - means 3 spaces between row elements (numbers are integers)- means 5 spaces between row elements and only one number after floating point |
Numpy Array Attributes
|
Array Indexing
We can access multiple matrix rows and columns when both row and columns are lists : x2[[1,2],[1,1]] -> this means access # Second and Third row ([1,2]) , Second and Second column |
Reshaping of Arrays
It is very important to note that number of rows multiplied by the number of columns must be equal to the number of array elements |
Array Concatenation and Splitting
NOTE : concatenate or stack vertically : must have same number of columns concatenate or stack horizontally : must have same number of rows NOTE 2 : The number of split points when splitting an array depends on the number of arrays generated where : Number of split points = number of arrays outputted - 1 -> split on the third element to x1 , split on the fifth element to x2 (from forth element) , give the rest to x3 |
Numpy Operations & UFuncs
For matrix dot operation, the number of columns in the first matrix (array) must be equal to the number of rows in the second matrix (array). |
Aggregates Types
The aggregate for multiplication is : array.multiply.reduce() The aggregate for subtraction is : array.subtract.reduce() The aggregate for division is : array.divide.reduce() The aggregate for addition array.add.reduce() is equivalent to np.sum(array) The aggregate for multiplication array.multiply.reduce() is equivalent to np.prod(array) |
Other Aggregate Function
|
Python Broadcasting
if any of these rules doesn't apply then broadcasting is not possible |
Numpy Fancy Indexing
In fancy indexing we can either put a list of indices or numpy array of indices |
Numpy Sorting
|
Array as a Data Structure
The Format For Empty Structured Arrays are as follows : - Integer : np.int32 or 'i4' - Float : np.float32 or 'f8' - String : np.str_ or 'U10' |