[英]numpy how to remove elements in one array based on boolean conditions from another array
I have an array xi我有一个数组 xi
xi=
[[ 0.49671415 -0.46341769]
[-0.1382643 -0.46572975]
[ 0.64768854 0.24196227]
[ 1.52302986 -1.91328024]
[-0.23415337 -1.72491783]
[-0.23413696 -0.56228753]
[ 1.57921282 -1.01283112]
[ 0.76743473 0.31424733]
[-0.46947439 -0.90802408]
[ 0.54256004 -1.4123037 ]]
then another array yi然后另一个数组 yi
[0 0 0 0 0 0 0 0 1 1 1]
how do I slice the xi array into 2 based on 0 and 1 in yi?如何根据 yi 中的 0 和 1 将 xi 数组分割成 2? how can i have我怎么能有
x1=
[[ 0.49671415 -0.46341769]
[-0.1382643 -0.46572975]
[ 0.64768854 0.24196227]
[ 1.52302986 -1.91328024]
[-0.23415337 -1.72491783]
[-0.23413696 -0.56228753]
[ 1.57921282 -1.01283112]
and和
x2=
[ 0.76743473 0.31424733]
[-0.46947439 -0.90802408]
[ 0.54256004 -1.4123037 ]]
Thank you for your help!谢谢您的帮助!
You can use:您可以使用:
x1 = xi[~yi.astype(bool)]
x2 = xi[yi.astype(bool)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.