I have bunch of int values that I have to read from a file and store it in a numpy array. This is how I am doing it:
el_connect = np.zeros([NEls,3],dtype=int)
for i in range(0,NEls):
connct = file.readline().strip().split()
for j in range(0,len(connct)):
el_connect[i,j] = int(connct[j])
This is how I am currently doing it. Is there a better way to do it where I can eliminate the second for loop?
Other questions I have regarding this are:
How can I deal with the scenario where certain columns are ints and other columns are floats because numpy arrays cannot handle multiple data types?
Also, how can I throw exception if the format of the file is not as I expected? Just a few examples would do.