首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >np.where与np.logical_and崩溃

np.where与np.logical_and崩溃
EN

Stack Overflow用户
提问于 2022-01-18 01:59:28
回答 2查看 78关注 0票数 0

我使用numpy来构建复杂的excel,如果公式的第一个条件如下:

代码语言:javascript
复制
DebitCond1 = np.where(np.logical_and(df['Debit']<0, df['Credit']<0, df['Debit']<df['Credit']))

Python每次运行时都会崩溃(在多台机器上尝试)。有两个条件是好的,但这三个条件的结合似乎是有争议的。

错误消息如下:

Python已经停止工作

一个问题导致程序停止正常工作。如果有可用的解决方案,Windows将关闭程序并通知您。

对原因和如何解决有任何想法吗?谢谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-01-29 17:39:38

This answer完全解决了上述场景,并提供了链接条件、np.reduce条件、functools.reduce条件或用显式轴替换所有条件的选项。

正因如此

DebitCond1a=np.logical_and(df['P1_DR']<0, df['P1_DR']<df['P1_CR'])

DebitCond1=np.logical_and(DebitCond1a,df['P1_CR']<0)

是在这种情况下合并多个条件的一种方法。

票数 0
EN

Stack Overflow用户

发布于 2022-01-18 02:03:40

您正在向np.logical_and()提供三个值。第三个被解释为out=参数,您可能并不打算这样做。

这是np.logical_and()的签名

代码语言:javascript
复制
numpy.logical_and(x1, x2, /, out=None, *, where=True,
                  casting='same_kind', order='K', dtype=None,
                  subok=True[, signature, extobj])

还有一份文件的摘录:

代码语言:javascript
复制
Compute the truth value of x1 AND x2 element-wise.

Parameters
----------
x1, x2 : array_like
    Input arrays.
    If ``x1.shape != x2.shape``, they must be broadcastable to a common
    shape (which becomes the shape of the output).
out : ndarray, None, or tuple of ndarray and None, optional
    A location into which the result is stored. If provided, it must have
    a shape that the inputs broadcast to. If not provided or None,
    a freshly-allocated array is returned. A tuple (possible only as a
    keyword argument) must have length equal to the number of outputs.
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70749506

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档