博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
numpy数组与布尔数组_数组和布尔
阅读量:2514 次
发布时间:2019-05-11

本文共 1583 字,大约阅读时间需要 5 分钟。

numpy数组与布尔数组

One of the annoyances of old-school JavaScript was side effects; then Array.prototype got methods like filter, map, and forEach so we didn't need to burn variables before looping over values.  I can't explain how happy I am that the JavaScript language continues to evolve.

老式JavaScript的烦恼之一是副作用。 然后Array.prototype获得了filtermapforEach类的方法,因此我们不需要在遍历值之前刻录变量。 我无法解释JavaScript语言的不断发展让我多么高兴。

Every once in a while I need to filter an array by not its original value but instead a new value, so I use map:

每过一段时间,我需要进行过滤而不是它的原始值的阵列,而是一个新的价值,所以我使用map

myArray.map(item => {    // Do whatever processing...    // If we don't care about the item, return false or null or undefined    return false;});

While I get the new values I want, sometimes if an iteration returns a result I don't want, I return null or false, which is great, but then I'm left with a bunch of useless items in the resulting array.  The next step is using filter, in which case I could do:

当我获得所需的新值时,有时如果迭代返回了我不想要的结果,我将返回null或false,这很好,但是随后在结果数组中留下了一堆无用的项。 下一步是使用过滤器,在这种情况下,我可以这样做:

myArray    .map(item => {        // ...    })    // Get rid of bad values    .filter(item => item);

Since the values I don't want aren't truthy, the filter above removes those bad items.  Did you know there's a clearer way with Boolean?

由于我不想要的值不真实,因此上面的过滤器删除了这些不良项。 您是否知道Boolean有更清晰的方法?

myArray    .map(item => {        // ...    })    // Get rid of bad values    .filter(Boolean);

If the value isn't truthy the item is filtered out and I'm left with only the items I want!

如果值不正确,该项目将被过滤掉,而我只剩下我想要的项目!

翻译自:

numpy数组与布尔数组

转载地址:http://suvwd.baihongyu.com/

你可能感兴趣的文章
java开发操作系统内核:由实模式进入保护模式之32位寻址
查看>>
第五讲:单例模式
查看>>
Python编程语言的起源
查看>>
Azure ARMTemplate模板,VM扩展命令
查看>>
使用Masstransit开发基于消息传递的分布式应用
查看>>
[CF808A] Lucky Year(规律)
查看>>
关于推送遇到的一些问题
查看>>
寒假作业3 抓老鼠啊~亏了还是赚了?
查看>>
Orcal Job创建实例
查看>>
Django
查看>>
批量Excel数据导入Oracle数据库(引用 自 wuhuacong(伍华聪)的专栏)
查看>>
处理移动障碍
查看>>
优化VR体验的7个建议
查看>>
2015年创业中遇到的技术问题:21-30
查看>>
《社交红利》读书总结--如何从微信微博QQ空间等社交网络带走海量用户、流量与收入...
查看>>
JDK工具(一)–Java编译器javac
查看>>
深入.NET框架与面向对象的回顾
查看>>
改变label中的某字体颜色
查看>>
七牛云存储之应用视频上传系统开心得
查看>>
struts2日期类型转换
查看>>