I am a beginner and will appreciate any alternatives to handle my problem. Simply put, I have two files, containing one vector each. Aim is to subtract all the elements of file 2 from file 1; for all possible combinations. Everything is fine for small vectors, everything is fine, but the processing time is huge for larger file such as with million elements in each file.
Given below is the minimal working example. I heard about memorymapping and would appreciate if you can share a modified version or any relevant pointers to handle this issue.
import matplotlib.pyplot as plt
import numpy as np
file1 = np.loadtxt('File_1.txt',delimiter=',')
file2 = np.loadtxt('File_2.txt',delimiter=',')
event1 = file1[:,1]
event2 = file2[:,1]
r1 = len(event1)
r2 = len(event2)
diff = []
for i in range(0,r1):
for j in range(0,r2):
delta = float(event1[i]-event2[j])
if delta >=-4000 and delta <=4000:
diff = np.append(diff, delta)
np.savetxt('export.txt', diff)