小编kkg*_*arg的帖子

PIL 类型错误:无法处理此数据类型:(1, 1, 1),|u1

我有一个numpy.ndarray形状(1,28,28),值是 [0,1] 范围内的浮点。我的最终目标是将数组保存为 png 图像。

即使在转置数组并将其与 255 相乘以获得 uint 值之后,它仍然会抛出错误*** TypeError: Cannot handle this data type: (1, 1, 1), |u1

我正在使用以下代码:

im = Image.fromarray((img.transpose(1,2,0) * 255).astype(np.uint8))
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激。

PS我已经在这里研究过这个建议。

arrays numpy image python-imaging-library numpy-ndarray

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

为什么我在 pdb 内无法访问 self.<method>

考虑这样的代码片段:

class ABC:
    def method1(self, word):
             ...

    def method2(self):
        str_list = ['this', 'is', 'a', 'list', 'of', 'strings']
        pdb.set_trace()
        str_list = [self.method1(word) for word in str_list] ...(1)

obj = ABC()
obj.method2()
Run Code Online (Sandbox Code Playgroud)

在断点处,当我将命令复制粘贴(1)到 pdb 调试器 shell 中时,它无法执行该命令,而是给出了错误:

*** NameError: name 'self' is not defined
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮助我理解这种行为 - 它与列表理解和类对象的范围有关吗?


PS C:\fooProjects> & C:/Python38/python.exe c:/fooProjects/tmp.py
> c:\fooprojects\tmp.py(38)method2()
-> str_list = [self.method1(word) for word in str_list]
(Pdb) [self.method1(word) for word in str_list]
*** NameError: name 'self' is not defined
(Pdb)
Run Code Online (Sandbox Code Playgroud)

python scope pdb

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

使用 Plotnine 拟合非线性曲线

这是一个为某些用户定义的指标生成线性曲线的工作示例。在此输入图像描述

如何将其拟合为非线性曲线?

def plot(version, str_metric):
  metric1 = [0.459, 0.5844, 0.6246, 0.6459, 0.6429, 0.6629, 0.664, 0.6722, 0.6832, 0.6931, 0.7103, 0.7144, 0.7213, 0.716, 0.7182, 0.7419, 0.7418, 0.7594, 0.7639, 0.7854, 0.7752, 0.7912, 0.8164, 0.8311,
             0.8283, 0.8103, 0.869, 0.8708, 0.884, 0.9017, 0.9248, 0.9233, 0.9432, 0.9306, 0.945, 0.959, 0.9675, 0.9649, 0.982, 0.9276, 0.975, 0.9772, 0.9786, 0.988, 0.9825, 0.9901, 0.9934, 0.993, 0.9956, 0.9951]
  metric2 = [0.4541, 0.5807, 0.6138, 0.6339, 0.6322, 0.63, 0.6451, 0.6514, 0.6589, 0.6597, 0.6759, 0.6817, 0.6866, 0.6803, 0.6819, 0.7009, 0.7039, 0.7162, 0.7197, 0.7237, …
Run Code Online (Sandbox Code Playgroud)

python plot ggplot2 python-ggplot plotnine

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