如何在mathematica中获取列表中奇怪索引的元素
如何获取列表中奇怪索引的元素?我正在考虑选择,但没有找到任何返回元素位置的内容,特别是考虑到列表中存在重复元素。
一般来说,如何选择那些索引满足某些条件的元素?
How to get the oddly indexed elements in a list? I am thinking of Select, but did not find anything returning an element's position, especially considering there are repetitive elements in the list.
Also in general, how to select those elements whose indices satisfy some certain conditions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除了 @belisarius的答案,不需要计算
Length[lis]
:您通常可以使用
-1
来表示“最后”位置。Here's a few more in addition to @belisarius's answer, which don't require computing
Length[lis]
:You can often use
-1
to represent the "last" position.有很多方法,以下是其中一些:
一般来说,使用 Pick[] (作为示例),您可以对任何可以想象的索引掩码进行建模。
There are a lot of ways, here are some of them:
In general, with Pick[] (as an example) you can model any conceivable index mask.
由于某种原因,答案中省略了
Span
的简洁形式。引用文档:
For some reason the terse form of
Span
has been omitted from the answers.Quoting the documentation: