尝试在APL中使用数组时出现问题.我错过了什么? [英] Problems when trying to use arrays in APL. What have I missed?
问题描述
我显然错过了一些有关如何从APL中的数组中提取元素的事情,希望有人可以看到我错过的事情,以及应该如何做才能以有意义的方式重现预期的结果.
I obviously have missed some things about how to extract elements from arrays in APL and hope that someone can see what I have missed and how I should do to get the expected results in a way that I can reproduce in a meaningful way.
我在学习APL方面相对较新,并且更习惯于Python和C之类的语言.APL中的数据类型和数组操作工具似乎使我有些困惑.
I am relatively new in learning APL and I am more used to languages like Python and C. The data types and array manipulating tools in APL seem to confuse me, a little.
考虑以下代码,并请说明为什么预期的结果(对我而言)
Consider the following code and please tell why the expected (by me) result,
┌→─────┐
│42 666│
└~─────┘
嵌入到更复杂的内容中,并且可能是一种解决方法 这个问题. (使用Dyalog APL/S-64,16.0.30320)
got embedded in something more complex, and possibly a way around that problem. (Using Dyalog APL/S-64, 16.0.30320)
⎕io ← 0
a ← 17 4711 (42 666)
z ← a[2]
an_expected_vector←42 666
]DISPLAY an_expected_vector
┌→─────┐
│42 666│
└~─────┘
]DISPLAY z
┌──────────┐
│ ┌→─────┐ │
│ │42 666│ │
│ └~─────┘ │
└∊─────────┘
为什么z
与an_expected_vector
不相同?
谢谢!/汉斯
推荐答案
2
是一个标量,因此a[2]
返回一个标量,它恰好是向量42 666
.因此,它被嵌套在一个嵌套层中.
2
is a scalar and so a[2]
returns a scalar, which happens to be the vector 42 666
. It is therefore enclosed in a level of nesting.
如果使用拾取"功能(二进位⊃
),您将获得预期的结果,因为⊃
将从右边的参数中选择左边的参数指示的元素:
If you use the Pick function (dyadic ⊃
) you will get the expected result, as ⊃
will pick the element indicated by the left argument, from the right argument:
⎕io ← 0
a ← 17 4711 (42 666)
z ← 2⊃a
an_expected_vector ← 42 666
z ≡ an_expected_vector
1
Try it online!
这篇关于尝试在APL中使用数组时出现问题.我错过了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!