Instead of using a for-loop, use
tsteps = np.arange(1,500,1, dtype='int64')*t*10**9
to build a NumPy array. Note carefully that NumPy arrays have a dtype. The dtype determines the range of numbers representable by the elements in the array. For example, with dtype int64, an array can represent all integers between
In [35]: np.iinfo('int64').min, np.iinfo('int64').max
Out[35]: (-9223372036854775808L, 9223372036854775807L)
For the sake of speed, NumPy does not check for arithmetic overflow.
If 499*t*10**9 falls outside this range, then the array will contain wrong numbers. So the onus is on you to choose the right dtype to avoid arithmetic overflow.
Note also that if t is a float, then np.arange(1,500,1, dtype='int64')*t will get upcasted to dtype float64, whose range of representable values lie between
In [34]: np.finfo('float64').min, np.finfo('float64').max
Out[34]: (-1.7976931348623157e+308, 1.7976931348623157e+308)
np.sum(Itarray*detarray) does not depend on tstep, so it can be pulled outside the for-loop. Or, since we are not using a for-loop, it just needs to be computed once.
Finally, form a 2D array (using np.column_stack), and save it to a file with np.savetxt:
import numpy as np
tsteps = np.arange(1,500,1, dtype='int64')*t*10**9
Intensity = np.sum(Itarray*detarray)
np.savetxt(filename, np.column_stack(tsteps, Intensity.real), delimiter='\t')
python-3.xwhile the code is Python 2.x code.