How to use the function numpy.append

后端 未结 1 792
野趣味
野趣味 2020-12-18 19:43

I have a problem using the function numpy.append. I wrote the following function as part of a larger piece of code, however, my error is reproduced in the folowing:

相关标签:
1条回答
  • 2020-12-18 19:57

    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.

    0 讨论(0)
提交回复
热议问题