小编dra*_*bob的帖子

如何在 Flask Restx 中建模 OneOf?

我有以下架构文档

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "title": "foo",
    "definitions": {
        "stuff": {
            "type": "object",
            "properties": {
                "id": {
                    "description": "the id",
                    "type": "string"
                },
                "type": {
                    "description": "the type",
                    "type": "string"
                }
            },
            "oneOf": [{
                "required": ["id"]
            }, {
                "required": ["type"]
            }],
        },
    },
    "type": "object",
    "properties": {
        "bar": {
            "description": "blah",
            "type": "object",
            "additionalProperties": {
                "$ref": "#/definitions/stuff"
            }
        }
    },
    "required": ["bar"]
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试创建 Flask Restx 模型,但我不确定如何对所需的 OneOf 字段进行建模?

我认为以下内容可行,但它忽略了 oneof 要求。

stuff_model = (
    "Stuff Model",
    "id": fields.String(description="the id", required=False), …
Run Code Online (Sandbox Code Playgroud)

python flask-restx

9
推荐指数
0
解决办法
682
查看次数

如何计算numpy数组中图像的平均颜色?

我有一个已转换为numpy数组的RGB图像.我正在尝试使用numpy或scipy函数计算图像的平均RGB值.

RGB值表示为0.0 - 1.0的浮点,其中1.0 = 255.

样本2x2像素image_array:

[[[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]],
 [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0]]]
Run Code Online (Sandbox Code Playgroud)

我试过了:

import numpy
numpy.mean(image_array, axis=0)`
Run Code Online (Sandbox Code Playgroud)

但是那个输出:

[[0.5  0.5  0.5]
 [0.5  0.5  0.5]]
Run Code Online (Sandbox Code Playgroud)

我想要的只是单个RGB平均值:

[0.5  0.5  0.5]
Run Code Online (Sandbox Code Playgroud)

python numpy image-processing

8
推荐指数
1
解决办法
2万
查看次数

如何使用 Poetry 在 python 轮子中包含符号链接和链接文件?

我有一个 python 包,我想包含子模块中的一些特定文件,而不包含整个包,因此结构如下所示:

foo_project
 |
 +-- submodule_files
     +-- bar.json
     +-- other_stuff
 +-- foo
     +-- __init__.py
     +-- foo.py
     +-- <symlink to bar.json>
Run Code Online (Sandbox Code Playgroud)

诗歌 toml 文件有

packages = [
    { include = "foo" }
]
Run Code Online (Sandbox Code Playgroud)

使用 创建轮子时poetry build,会复制链接的文件,但不会复制链接本身

 foo_wheel
 |
 +-- submodule_files
     +-- bar.json
 +-- foo
     +-- __init__.py
     +-- foo.py
Run Code Online (Sandbox Code Playgroud)

(为简洁起见,省略了wheel中的信息目录)

因此,一旦安装,python 包就缺少额外的文件

python-3.x python-poetry

8
推荐指数
0
解决办法
1016
查看次数

如何使用广播从具有列表 2d 索引的 2D numpy 数组中获取元素?

如果我有一个 2D numpy 数组,我想使用行、列索引对列表来提取元素。

xy = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
idx = np.array([[0, 0], [1, 1], [2, 2]])
Run Code Online (Sandbox Code Playgroud)

for循环解决方案:

elements = list()
for i in idx:
    elements.append(xy[idx[i][0], xy[idx[i][1])
Run Code Online (Sandbox Code Playgroud)

输出:

print(elements)
>> [1, 5, 9]
Run Code Online (Sandbox Code Playgroud)

如果 idx 是元组列表,我找到了解决方案,但我希望找到一个不需要先将 idx 转换为元组的解决方案。

numpy python-2.7 array-broadcasting

5
推荐指数
1
解决办法
2227
查看次数