numpy dtype错误 - (结构化数组创建)(numpy dtype error - (structured array creation))
我无法理解为什么以下不起作用:
np.dtype(dict(names="10", formats=np.float64))
我一直在努力解决这个问题,因为我
recfunctions
numpy
的recfunctions
函数工作,但是由于numpy.dtype
问题,我没有成功。 这是我目前收到的错误:dtype = np.dtype(dict(names=names, formats=formats)) ValueError: all items in the dictionary must have the same length.
我想获得一个数据结构,其中包含一种记录数组,每个指定字段中包含多列数据 - 类似于字典,其中每个值是一个二维数组或几列数据。 通常,数据可能最终为~6列,每个键或记录约2000行,具有约200个记录。
这是我在一个完整的脚本中尝试过的:(虽然仍然给出相同的错误)
import numpy as np from numpy.lib import recfunctions # Just function to make random data def make_data(i, j): # some arbitrary function to show that the number of columns may change, but rows stay the same length if i%3==0: data = np.array([[i for i in range(0,1150)]*t for t in range(0,3)]) else: data = np.array([[i for i in range(0,1150)]*t for t in range(0,6)]) return data def data_struct(low_ij, high_ij): """ Data Structure to contain several columns of data for different combined values between "low ij" and "high ij" Key: "(i, j)" Value: numpy ndarray (multidimensional) """ for i in range(0,low_ij+1): for j in range(0,high_ij+1): # Get rid of some of the combinations # (unimportant) if(i<low_ij and j<low_ij): break elif(i<j): break # Combinations of interest to create structure else: names = str(i)+str(j) formats = np.float64 data = np.array(make_data(i, j)) try: data_struct = recfunctions.append_fields(base=data_struct, names=names, data=data, dtypes=formats) # First loop will assign data_struct using this exception, # then proceed to use the try statement to add on the rest of the data except UnboundLocalError: dtype = np.dtype(dict(names=names, formats=formats)) data_struct = np.array(data, dtype=dtype) return data_struct
I am having some trouble understanding why the following does not work:
np.dtype(dict(names="10", formats=np.float64))
I have been struggling with this because I would like to get the
recfunctions
function innumpy
to work, but due to issues with thenumpy.dtype
, I haven't been successful. This is the error I am receiving at the moment:dtype = np.dtype(dict(names=names, formats=formats)) ValueError: all items in the dictionary must have the same length.
I want to get a data structure that will contain a type of record array with multiple columns of data within each assigned field - similar to a dictionary where each value is a 2d array or several columns of data. Typically the data may end up being ~6 columns, ~2000 rows for each key or record, with ~200 records.
Here is what I have tried in a complete script: (although still giving the same error)
import numpy as np from numpy.lib import recfunctions # Just function to make random data def make_data(i, j): # some arbitrary function to show that the number of columns may change, but rows stay the same length if i%3==0: data = np.array([[i for i in range(0,1150)]*t for t in range(0,3)]) else: data = np.array([[i for i in range(0,1150)]*t for t in range(0,6)]) return data def data_struct(low_ij, high_ij): """ Data Structure to contain several columns of data for different combined values between "low ij" and "high ij" Key: "(i, j)" Value: numpy ndarray (multidimensional) """ for i in range(0,low_ij+1): for j in range(0,high_ij+1): # Get rid of some of the combinations # (unimportant) if(i<low_ij and j<low_ij): break elif(i<j): break # Combinations of interest to create structure else: names = str(i)+str(j) formats = np.float64 data = np.array(make_data(i, j)) try: data_struct = recfunctions.append_fields(base=data_struct, names=names, data=data, dtypes=formats) # First loop will assign data_struct using this exception, # then proceed to use the try statement to add on the rest of the data except UnboundLocalError: dtype = np.dtype(dict(names=names, formats=formats)) data_struct = np.array(data, dtype=dtype) return data_struct
原文:https://stackoverflow.com/questions/27947763
最满意答案
我不熟悉python API,但不应该创建自己的QPickingSettings实例,而应该使用作为QRenderSettings实例(即单例)的属性存在的实例。
如果您使用的是Qt3DExtras中的Qt3DWindow,它将为QRenderSettings实例提供一个访问器。
否则,您需要创建一个QRenderSettings实例并将其添加为实体的一个组件。 按照惯例,我们倾向于使用场景图的根。
I'm not familiar with the python API, but you should not create your own instance of QPickingSettings but use the one that exists as a property of the instance of QRenderSettings (that is a singleton).
If you're using the Qt3DWindow from Qt3DExtras, it will provide an accessor to the QRenderSettings instance.
Otherwise, you'll need to create an instance of QRenderSettings and add it as a component of an entity. By convention we tend to use the root of the scene graph.
相关问答
更多-
你有没有看过QRenderSettings类的枚举 ? 看起来您可以将渲染策略设置为OnDemand ,这会导致Qt只在渲染场景时渲染。 或者,如果您不需要与场景交互,则可以查看我的脱机渲染器实现 。 每当您设置根实体时,基础QAspectEngine启动并停止。 您可以设置您的根实体,捕获框架并取消设置根实体,导致图形循环停止,这会导致CPU负载减少,我猜测。 Did you have a look at the enum of the QRenderSettings class? It seems li ...
-
window.h文件应该位于Qt\Examples\Qt-5.5\qt3d\common文件夹中,它与Windows无关,只对QWindow 。 更多细节在这里: https : //forum.qt.io/topic/56554/qt-5-5-qt3d-window-h-file-in-the-examples 如果在您的项目中找不到此路径,则可以将其添加到.pro文件中: INCLUDEPATH += "Qt/Examples/Qt-5.5/qt3d/common" 阅读更多关于在Qt Creator ...
-
使用Qt3D与Qt5(Using Qt3D with Qt5)[2022-05-20]
问题必须与QtCreator有关。 使用qmake成功地直接构建库,而使用QtCreator失败。 添加 QT += 3d 也有效 The problem must be related to QtCreator. Using qmake directly builds the library succesfully, while using QtCreator fail. Adding QT += 3d works too -
Qt3D中的QObjectPicker和设置PointPicking不起作用(QObjectPicker in Qt3D and setting PointPicking does not work)[2023-05-26]
我不熟悉python API,但不应该创建自己的QPickingSettings实例,而应该使用作为QRenderSettings实例(即单例)的属性存在的实例。 如果您使用的是Qt3DExtras中的Qt3DWindow,它将为QRenderSettings实例提供一个访问器。 否则,您需要创建一个QRenderSettings实例并将其添加为实体的一个组件。 按照惯例,我们倾向于使用场景图的根。 I'm not familiar with the python API, but you should n ... -
你必须pyqtProperty : angle = pyqtProperty(float, fget=angle, fset=setAngle, notify=angleChanged) radius = pyqtProperty(float, fget=radius, fset=setRadius, notify=radiusChanged) target = pyqtProperty(QTransform, fget=target, fset=setTarget, notify=targetChange ...
-
在Qt3D中无法直接调用glBlendFunc 。 您需要设置RenderPass的renderStates属性。 它应该与此类似,具体取决于您要启用的混合函数和其他状态: renderPasses: [ RenderPass { filterKeys: [ FilterKey { name: "pass"; value: "forward" } ] renderStates: [ CullFace { mode : CullFace.Back ...
-
在Qt3D中访问帧缓冲区(Access framebuffer in Qt3D)[2022-05-31]
你可以为此使用QRenderCapture 。 这基本上为你做了一个glReadPixels 。 这个文档有点稀疏,但有一个例子在线。 另外,我实现了一个离线渲染器 ,它可以帮助你防止你不想要一个完整的3D窗口。 我不确定你的意思 计算3D网格的像素坐标(例如制作快照)以从特定摄像机角度查找此网格的2D形状 但是如果你想例如只用一种颜色渲染整个网格(没有突出显示),你可以试试QPerVertexColorMaterial ,它给了我完全的结果。 You can use QRenderCapture for ... -
我有办法成功: 首先我下载了最新版本的Qt,Qt 5.2.1 我使用git客户端将“git://gitorious.org/qt/qt3d”中的Qt3D源代码下载到文件夹“C:\ qt3d”中 使用终端“Qt 5.2.1 for Desktop(MinGW 4.8 32 bit)” cd C:\qt3D qmake mingw32-make.exe install “安装”很重要,以便将所有文件复制到Qt配置文件夹中。 然后,在.pro文件中,添加 QT += 3d 在main.qml文件中: impo ...
-
正如我在评论中所写的那样,对于一个简单的问题,你有一个复杂的方法。 您应该在qmake项目文件中使用以下语句: QT += 3d 如果正确安装了Qt3D库,这将使事情自动运行。 As I wrote in the comment, you are having a complex approach for a simple issue. You should use the following statement in your qmake project file: QT += 3d This wil ...
-
我认为您必须访问您感兴趣的属性的QBuffer 。这可能不是defaultPositionAttributeName()的属性,而是您在导入器中提供的名称。 获取实际数据将要求您将其从QByteArray转换为正确的数据类型,并使用QAttribute的byteStride和QAttribute包含的信息获取数据中的正确位置。 您可能还想使用vertexSize和vertexBaseType ,具体取决于您编写导入程序的方式。 沿着这些方向的东西应该工作(未经测试): void ES3DScene::han ...