I have this following code that do help me reshape each lines in a file and perform simple division calculation. When divided by zero, this error occurred. Any helps are greatly appreciated.
print(np.sum(single / divisi * binary, axis = -1))
RuntimeWarning: divide by zero encountered in divide
print(np.sum(single / divisi * binary, axis = -1))
RuntimeWarning: invalid value encountered in multiply
Code
import numpy as np
from numpy import genfromtxt
import csv
binary = np.genfromtxt('binary.csv', delimiter = ',').reshape((-1, 101, 4))
single = np.genfromtxt('single.csv', delimiter = ',').reshape((-1, 4))
divisi = np.genfromtxt('divisi.csv', delimiter = ',').reshape((-1, 1, 4))
print(np.sum(single / divisi * binary, axis = -1))
The inclusion of this 4 lines or code still cannot solve it.
try:
print(np.sum(single / divisi * binary, axis = -1))
except Exception:
print(0)