<bdo id='OEzCJ'></bdo><ul id='OEzCJ'></ul>
      1. <i id='OEzCJ'><tr id='OEzCJ'><dt id='OEzCJ'><q id='OEzCJ'><span id='OEzCJ'><b id='OEzCJ'><form id='OEzCJ'><ins id='OEzCJ'></ins><ul id='OEzCJ'></ul><sub id='OEzCJ'></sub></form><legend id='OEzCJ'></legend><bdo id='OEzCJ'><pre id='OEzCJ'><center id='OEzCJ'></center></pre></bdo></b><th id='OEzCJ'></th></span></q></dt></tr></i><div id='OEzCJ'><tfoot id='OEzCJ'></tfoot><dl id='OEzCJ'><fieldset id='OEzCJ'></fieldset></dl></div>

        <small id='OEzCJ'></small><noframes id='OEzCJ'>

      2. <legend id='OEzCJ'><style id='OEzCJ'><dir id='OEzCJ'><q id='OEzCJ'></q></dir></style></legend>
        <tfoot id='OEzCJ'></tfoot>
      3. Numpy:按多个条件过滤行?

        时间:2023-08-29

        1. <small id='diO57'></small><noframes id='diO57'>

              <i id='diO57'><tr id='diO57'><dt id='diO57'><q id='diO57'><span id='diO57'><b id='diO57'><form id='diO57'><ins id='diO57'></ins><ul id='diO57'></ul><sub id='diO57'></sub></form><legend id='diO57'></legend><bdo id='diO57'><pre id='diO57'><center id='diO57'></center></pre></bdo></b><th id='diO57'></th></span></q></dt></tr></i><div id='diO57'><tfoot id='diO57'></tfoot><dl id='diO57'><fieldset id='diO57'></fieldset></dl></div>
                <bdo id='diO57'></bdo><ul id='diO57'></ul>
                <legend id='diO57'><style id='diO57'><dir id='diO57'><q id='diO57'></q></dir></style></legend>
                  <tfoot id='diO57'></tfoot>

                    <tbody id='diO57'></tbody>
                  本文介绍了Numpy:按多个条件过滤行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个名为 meta 的二维 numpy 数组,它有 3 列.我想要做的是:

                  I have a two-dimensional numpy array called meta with 3 columns.. what I want to do is :

                  1. 检查前两列是否为零
                  2. 检查第三列是否小于 X
                  3. 只返回符合条件的行

                  我做到了,但解决方案似乎很做作:

                  I made it work, but the solution seem very contrived :

                  meta[ np.logical_and( np.all( meta[:,0:2] == [0,0],axis=1 ) , meta[:,2] < 20) ]
                  

                  你能想出更清洁的方法吗?似乎很难同时拥有多个条件;(

                  Could you think of cleaner way ? It seem hard to have multiple conditions at once ;(

                  谢谢

                  对不起,我第一次复制了错误的表达方式……已更正.

                  Sorry first time I copied the wrong expression... corrected.

                  推荐答案

                  你可以在一个切片中使用多个过滤器,像这样:

                  you can use multiple filters in a slice, something like this:

                  x = np.arange(90.).reshape(30, 3)
                  #set the first 10 rows of cols 1,2 to be zero
                  x[0:10, 0:2] = 0.0
                  x[(x[:,0] == 0.) & (x[:,1] == 0.) & (x[:,2] > 10)]
                  #should give only a few rows
                  array([[  0.,   0.,  11.],
                         [  0.,   0.,  14.],
                         [  0.,   0.,  17.],
                         [  0.,   0.,  20.],
                         [  0.,   0.,  23.],
                         [  0.,   0.,  26.],
                         [  0.,   0.,  29.]])
                  

                  这篇关于Numpy:按多个条件过滤行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:pandas 数据框条件 .mean() 取决于特定列中的值 下一篇:Python3有条件地装饰?

                  相关文章

                  1. <legend id='5RMuP'><style id='5RMuP'><dir id='5RMuP'><q id='5RMuP'></q></dir></style></legend>

                    <tfoot id='5RMuP'></tfoot>
                  2. <i id='5RMuP'><tr id='5RMuP'><dt id='5RMuP'><q id='5RMuP'><span id='5RMuP'><b id='5RMuP'><form id='5RMuP'><ins id='5RMuP'></ins><ul id='5RMuP'></ul><sub id='5RMuP'></sub></form><legend id='5RMuP'></legend><bdo id='5RMuP'><pre id='5RMuP'><center id='5RMuP'></center></pre></bdo></b><th id='5RMuP'></th></span></q></dt></tr></i><div id='5RMuP'><tfoot id='5RMuP'></tfoot><dl id='5RMuP'><fieldset id='5RMuP'></fieldset></dl></div>

                    <small id='5RMuP'></small><noframes id='5RMuP'>

                      <bdo id='5RMuP'></bdo><ul id='5RMuP'></ul>