首页 \ 问答 \ numpy dtype错误 - (结构化数组创建)(numpy dtype error - (structured array creation))

numpy dtype错误 - (结构化数组创建)(numpy dtype error - (structured array creation))

我无法理解为什么以下不起作用:

np.dtype(dict(names="10", formats=np.float64))

我一直在努力解决这个问题,因为我recfunctions numpyrecfunctions函数工作,但是由于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 in numpy to work, but due to issues with the numpy.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
更新时间:2022-07-04 20:07

最满意答案

我不熟悉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 ...
  • 问题必须与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
  • 我不熟悉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 ...
  • 你可以为此使用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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)