Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
def square_sum(a,b):
    return(a*a+b*b)
fname="filename.dat"
fp=open(fname,'w')
for a in range(1000):
    for b in range(1000):
        s=str(a)+' '+str(b)+' '+str(square_sum(a,b))+'\n'
        fp.write(s)
fp.close()

This will write the data to a filename named "filename.dat". You can also give a path if you wish.

To read it from another notebook use the following code

import numpy as np
array=np.genfromtxt('/path-to-file/filename.dat',delimiter='')

Of course you have to replace 'path-to-file' by whatever path it is. Now you can use array the way we usually use arrays.

I hope this helps.