numpy masked array

import numpy as npa = np.arange(5)print(a)x = np.ma.array(a,mask=[[9,9,9,9,9]])print(x)y = np.ma.array(a,mask=[[0,1,0,1,0]])print(y) Output[0 1 2 3 4][– — — — –][0 — 2 — 4]

Threading demo

from threading import *from time import * class Calc: def __init__(self,n1,n2):        self.num1 = n1       self.num2 = n2 def add(self):        print(self.num1 + self.num2) def subtract(self):        print(self.num1 – self.num2) obj1 = Calc(8,2)obj2 = Calc(10,3) ThreadAdd1 = Thread(target=obj1.add)ThreadAdd2 = Thread(target=obj2.add) ThreadAdd1.start()print()ThreadAdd2.start() ThreadSub1 = Thread(target=obj1.subtract)ThreadSub2 = Thread(target=obj2.subtract) ThreadSub1.start()print()ThreadSub2.start()Continue reading “Threading demo”

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”