小编Sve*_*ito的帖子

pyautogui,截图功能无法识别已安装的 Pillow 模块

我想在 Pycharm 中执行这段代码

x, y = pyautogui.locateCenterOnScreen('LVL35.png')
Run Code Online (Sandbox Code Playgroud)

但我收到这条消息

ImportError: Pillow module must be installed to use screenshot functions on Windows.
Run Code Online (Sandbox Code Playgroud)

问题是,我使用 anaconda 并且已经安装了 Pillow,我也可以在 Project Interpreter 设置中找到它。

Requirement already satisfied: Pillow in c:\anaconda3\lib\site-packages (4.2.1)
Run Code Online (Sandbox Code Playgroud)

任何的想法?

在此处输入图片说明

python importerror pillow pyautogui

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

每个面板中facet_grid 中的唯一y 轴(行和列)

我正在努力让每个面板都有facet_grid自己的 y 轴。

\n\n

所以基本上我希望该图的所有子图都有自己的 y 轴(以便您实际上可以看到数据)。同时,我希望每列都有一个固定的 x 轴,就像现在一样。条带标签也应该像现在这样。

\n\n

在此输入图像描述

\n\n
\n\n

我尝试使用facet_wrap它,这确实会给每个面板自己的 y 轴。但后来我很难修复每列的 x 轴。scales="free_y"修复所有面板中的 x 轴,而不是像 中那样每列facet_grid。另外,我得到strip labels了每个子图,这也是我不想要的。

\n\n

\n\n

在此输入图像描述

\n\n
\n\n

这是我与一些示例数据一起使用的代码的相关部分,这些数据应该足以构建非常相似的图:

\n\n
BAAM = data.frame(Subject = rep(c("S1", "S2", "S3", "S4"), each=4),\n                      Feature = rep(c("Maximum negative\\namplitude [\xc2\xb5V]", "Duration [sec]", "Descending\\nslope [\xc2\xb5V/sec]", "Ascending\\nslope [\xc2\xb5V/sec]"), times=4),\n                      mean    = c(-200, 1, 1500, 1600, -210, 1.1, 1300, 1500, -250, 3, 1400, 1600, -50, 0.5, 1000, 1000),\n                      dif     = c(20, …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 facet-wrap facet-grid

5
推荐指数
0
解决办法
1129
查看次数

Python:以另一列为条件的数据框中列表的元素均值

我有一个看起来像这样的数据框,它有三列(10 个不同的刺激、16 个试验和一个包含等长列表的数据列)。我只想根据刺激获得数据列的元素均值。由于我有 10 个不同的刺激,它应该为每个刺激产生 10 个数组,这也是试验中所有数据数组的平均值。

在此处输入图片说明

我想过这样的事情,但它给了我一些非常奇怪的东西。

df.groupby('stimulus').apply(np.mean)
>> IndexError: tuple index out of range
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明


构建我的数据框

trial_vec       = np.tile(np.arange(16)+1, 10)     
stimulus_vec    = np.repeat([-2., -1.75, -1., -0.75, -0.5,  0.5,  1.,  1.25,  1.75,  2.5 ], 16)                  
data_vec        = np.random.randint(0, 16, size=160)
df              = pd.DataFrame({'trial': trial_vec, 'stimulus': stimulus_vec, 'data': data_vec}).astype('object')
df["data"]      = [np.random.rand(4).tolist() for i in range(160)]
df
Run Code Online (Sandbox Code Playgroud)

python mean apply pandas elementwise-operations

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

Cython:创建数组抛出“常量表达式中不允许”

我尝试将一个复杂的函数形式 Python 重写为 Cython 以大大加快它的速度,但遇到以下问题:在编译我的函数 hh_vers_vector.pyx 时使用

setup(
    ext_modules=cythonize("hh_vers_vector.pyx"),
)
Run Code Online (Sandbox Code Playgroud)

它引发以下错误

    cdef int numSamples = len(Iext);

    # initial values
    cdef float v[numSamples]
                      ^
    ------------------------------------------------------------

    hh_vers_vector.pyx:47:27: Not allowed in a constant expression
Run Code Online (Sandbox Code Playgroud)

但是,如果我将“numSamples”作为数字输入函数,则没有问题。我不明白,因为我认为 len(Iext) 也会返回一个数字 10.000 。那么为什么 Cython 对这个表达式有问题呢?

cdef float v[numSamples] # ERROR
cdef float v[10000]      # NO ERROR
Run Code Online (Sandbox Code Playgroud)

到目前为止,我的函数看起来像这样:

from math import exp
import time

def hhModel(*params, Iext, float dt, int Vref):

    ## Unwrap params argument: these variables are going to be optimized
    cdef float ENa = params[0]
    cdef …
Run Code Online (Sandbox Code Playgroud)

python arrays cython

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