'Fast way to generat a list of QVector3D's in python

I would like to use the Q3DSurface() class to plot my data. In the example, they use a loop to generate the data and convert it to a list of QVector3D() objects.

In my case, I have the data as a numpy.ndarray(). If I follow the example, I have to iterate through the entire array and convert every element to a QVector3D() and save it in a list.

Is there a more efficient way to generate a list of QVector3D() elements from a numpy array that I can pass to the QSurfaceDataProxy() object?

In my use case, I want to have a live view in a GUI. The updated takes with the code below roughly 0.3s (data.shape=(400,400)). This is way too much for my application.

I tried it with numba, but it does not recognize the QVector3D() class.

The code where I parse the array is:

#@jit(nopython=True)    
def update_data(data:np.ndarray):
    vector_list= [[0]*data.shape[1] for i in range(data.shape[0])]
    for y_index in range(data.shape[0]):
        for x_index in range(data.shape[1]):
            vector_list[y_index][x_index] = QVector3D(x_index, data[y_index,x_index], y_index)
    return vector_list


Solution 1:[1]

Here: https://doc.qt.io/qt-5/qtdatavisualization-data-handling.html, it says

Dealing with Real-time Data

When you have a data set that updates rapidly, it is important to handle data properly to ensure good performance. Since memory allocation is a costly operation, always use QList::reserve() and QVector::resize() where possible to avoid unnecessary reallocations when constructing the array to give to the proxy. If you need to change the entire data set for each frame, it is in most cases best to reuse the existing array - especially if the array dimensions do not change. If you need to add, insert, remove, or change several rows or items for each frame, it is always more efficient to do it with one method call instead of multiple calls affecting a single row or item each. For example, adding ten rows with a single QBarDataProxy::addRows() call is much more efficient than ten separate QBarDataProxy::addRow() calls.

Bars renderer is optimized to access only data that is within the data window and thus should not suffer noticeable slowdown even if more data is continually added to the proxy.

Due to the unsorted nature of the scatter data, any change in the data window ranges requires all data points to be checked for visibility, which can cause increasing slowdown if data is continually added to the proxy. For the best performance with the scatter graphs, only keep the data you need in the proxy.

Surface data, while on item level similar to scatter data, is already assigned into rows and columns, so the surface renderer can optimize drawing by making the assumption that the data in the rows and columns is sorted along their respective axes. It is not quite as efficient as in the bars case, but nearly so.

Are you using multiple rows at once or one by one?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 huseyin tugrul buyukisik