简体   繁体   English

Kernel 在使用 np.logical_and 后死亡

[英]Kernel dies after using np.logical_and

So I have created a sample dataset that is as follows:所以我创建了一个示例数据集,如下所示:

import numpy as np
import pandas as pd

x = range(1, 10)
arr1 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
arr2 = np.random.randint(x)
arr3 = np.random.randint(x)
arr4 = np.random.randint(x)


dict_df = {
    'arr1' : arr1,
    'arr2' : arr2,
    'arr3' : arr3,
    'arr4' : arr4
}


df = pd.DataFrame(dict_df)

When printed this works fine, though when I try to add:打印时效果很好,但是当我尝试添加时:

filt = np.logical_and(df['arr1']==0, df['arr2']==0, df['arr3']==0) 

the kernel dies, (at the top of the screen it says Dead Kernel) Any ideas? kernel 死了,(在屏幕顶部显示死内核)有什么想法吗? Thanks!谢谢!

np.logical_and takes only 2 parameters. np.logical_and只接受 2 个参数。 Try this instead试试这个

filt = (df['arr1']==0) & (df['arr2']==0) & (df['arr3']==0)
print(filt)

0    False
1    False
2    False
3    False
4    False
5    False
6    False
7    False
8    False
dtype: bool

use ufunc.reduce on np.logical_andufunc.reduce上使用np.logical_and

s = np.logical_and.reduce([df['arr1']==0, df['arr2']==0, df['arr3']==0])

Out[85]: array([False, False, False, False, False, False, False, False, False])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM