I am trying to adapt the basic structure of the build code (matplotlib), which is updated by timer to switch from using Python lists for graph data to using numpy arrays. I want to reduce the time step for the plot as much as possible, and since the data can get up to thousands of points, I begin to quickly lose valuable time if I can not. I know numpy arrays are preferred for this kind of thing, but it's hard for me to understand when I need to think as a Python programmer, and when I need to think as a C ++ programmer, maximizes memory access efficiency.
The scipy.org docs talk about the append () function, which returns a copy of the arrays attached together. Do all of these copies need to be properly garbage collected? For instance:
import numpy as np
a = np.arange(10)
a = np.append(a,10)
print a
This is my reading of what is happening at the C ++ level, but if I knew what I was talking about, I would not ask a question, so please correct me if I'm wrong! = P
First, a block of 10 integers is allocated, and the a symbol indicates the beginning of this block. Then a new block of 11 integers is allocated, in which 21 ints (84 bytes) are used. Then the pointer moves to the beginning of the 11-int block. I assume that this will cause the garbage collection algorithm to reduce the reference count of the 10-int block to zero and cancel it. It is right? If not, how can I guarantee that I do not create overhead when adding?
, numpy, . reset , . , del data[:]. numpy? data = np.array([]) , ?