how to display a numpy array with pyglet?

时光毁灭记忆、已成空白 提交于 2019-12-05 13:09:52

I think what you are looking for is np.dstack (or more generally, np.concatenate):

label255=label*255
label3=numpy.dstack((label255,label255,label255))

This shows dstack produces the same array (label3) as your construction for label_3d:

import numpy as np

label=np.random.random((100,100))
label255=label*255
label3=np.dstack((label255,label255,label255))

label_3d = np.empty([100,100,3])
label_3d[:,:,0] = label * 255            # value range of label is [0,1]
label_3d[:,:,1] = label * 255
label_3d[:,:,2] = label * 255
print(np.all(label3==label_3d))
# True

PS. I'm not sure, but have you tried using label3.data instead of ctypes.string_at(id(label3.tostring())+20, 100*100*3) ?

You can get the memory representation of your array with 3d_label.tostring().

The tostring() method allows you to change the memory ordering of the elements:

Parameters
----------
order : {'C', 'F', None}, optional
    Order of the data for multidimensional arrays:
    C, Fortran, or the same as for the original array.

PS: The 3d_label.data of ~unutbu requires less memory, since no string is constructed. However, it does not allow you to change the order in which the elements are output.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!