Numpy T attribute

from numpy import * arr = array([[10,20,30,40,50],[11,22,33,4,5]])print(‘Original array\n’,arr) print(‘\nTransposed array: ‘) print(arr.T) Output Original array[[10 20 30 40 50][11 22 33 4 5]] Transposed array: [[10 11][20 22][30 33][40 4][50 5]]

Numpy cumulative product

import numpy as np arr = np.array([[6, 1, 3], [8, 2, 1]]) print(‘2D Array\n’,arr) b = np.cumprod(arr, dtype=int) print(‘Cumulative product of all elements\n’,b) c = np.cumprod(arr,axis=0) print(‘Cumulative product of elements axis=0\n’,c) x = np.array([6, 1, 3]) print(‘Single dimension array ‘,x) y = np.cumprod(x, dtype=int) print(‘Single Dimension array Cumulative product of all elements\n’,y) Output 2D Array[[6Continue reading “Numpy cumulative product”

Matrix aggregate functions

from numpy import * x = matrix([[11,22,33],[44,55,66],[1,2,3]]) print(‘Matrix: \n’,x) print() print(‘Largest Element: ‘,x.max()) print() print(‘Smallest Element: ‘,x.min()) print() print(‘Sum: ‘,x.sum()) print() print(‘Mean: ‘,x.mean()) Output Matrix: [[11 22 33][44 55 66][ 1 2 3]] Largest Element: 66 Smallest Element: 1 Sum: 237 Mean: 26.333333333333332