How to use the function numpy.append
Unlike the list append
method, numpy's append
does not append in-place. It returns a new array with the extra elements appended. So you'd need to do r = np.append(r, float(line[index]))
.
Building up numpy arrays in this way is inefficient, though. It's better to just build your list as a Python list and then make a numpy array at the end.