APL Enclose with Axis:⊂[n]A 是如何工作的?
APL Enclose with Axis: How does ⊂[n]A work?
首先是一些代码:
A ← 2 2 2 ⍴ ⍳8
A
0 1
2 3
4 5
6 7
⊂[0]A
0 4 1 5
2 6 3 7
我可以想象在第一个轴上封闭意味着在其深度上对数组进行子切片,产生 [[0 1][2 3]]
& [[4 5][6 7]]
或者我可以认为它意味着在列上进行子切片,产生 [[0 2][4 6]]
& [[1 3][5 7]]
。但当然它也不起作用。 (⊂[1]A
做第二个,第一个做什么操作?)
⊂[axis]array
用于分割数组的底层算法是什么?我已经绘制了几个表格以查看是否可以为它建立直觉,但我一直无法并且无法在我查看的文档中找到此信息。
我将使用从一开始的索引——如果你想一起打字,你可以设置⎕IO。
轴规范中给出的尺寸将受到影响。也就是说,如果你包围第 n 个维度,排名将降低,因为结果的形状将是没有 n[=39= 的原始形状第 ] 个维度。
⍴a ← 2 3 4⍴⍬
2 3 4
⍴⊂[1]a
3 4
⍴⊂[2]a
2 4
⍴⊂[3]a
2 3
现在,第 n 个维度的数组将保留它们在保留维度上的位置,但作为标量包含(即 封闭 ) 它们,产生一个嵌套数组:
a ← 2 2 2⍴⍳8
a
1 2
3 4
5 6
7 8
⊂[1]a
┌→──┐ ┌→──┐
│1 5│ │2 6│
└───┘ └───┘
┌→──┐ ┌→──┐
│3 7│ │4 8│
└───┘ └───┘
What is the underlying algorithm that ⊂[axis]array
is using to
split the array? I've drawn out several tables to see if I could build
an intuition for it, but I've not been able to and I've not been able
to find this information in the documentation I've looked at.
对于您的示例,一个简单的直觉可能是想象两张印有 table 的半透明纸。你把它们放在彼此后面,稍微倾斜。然后,想象一下,如果在他们面前放一个光源,他们身后的墙上会投射出什么。您的结果是每个单元格中有两个值的预计平坦 table。
I can imagine enclosing on the first axis to mean sub-slicing the array on it's depth, yielding [[0 1][2 3]] & [[4 5][6 7]] or I could
see it meaning sub-slicing on columns, yielding [[0 2][4 6]] & [[1
3][5 7]]. But of course it doesn't do either. (⊂[1]A
does the
second,
它不仅仅是子切片 – 包含 returns 嵌套数组(简单标量除外)。我误解了你的符号,或者以下内容不清楚:
1 2 3
1 2 3
⍴1 2 3
3 ⍝ rank 1, i.e. a vector
≡⍴1 2 3
1 ⍝ depth 1, i.e. a non-nested array
⊂1 2 3
┌→────┐
│1 2 3│
└─────┘
⍴⊂1 2 3 ⍝ rank 0, i.e. a scalar
≡⊂1 2 3
2 ⍝ depth >1, i.e. a nested array
what operation would do the first?)
您可以围绕一组维度:
⊂[2 3]a
┌→──┐ ┌→──┐
↓1 2│ ↓5 6│
│3 4│ │7 8│
└───┘ └───┘
但是,如上所述 Z ← ⊂[X]R
、⍴⍴Z ←→ (⍴⍴R)-⍴⍴X
。
首先是一些代码:
A ← 2 2 2 ⍴ ⍳8
A
0 1
2 3
4 5
6 7
⊂[0]A
0 4 1 5
2 6 3 7
我可以想象在第一个轴上封闭意味着在其深度上对数组进行子切片,产生 [[0 1][2 3]]
& [[4 5][6 7]]
或者我可以认为它意味着在列上进行子切片,产生 [[0 2][4 6]]
& [[1 3][5 7]]
。但当然它也不起作用。 (⊂[1]A
做第二个,第一个做什么操作?)
⊂[axis]array
用于分割数组的底层算法是什么?我已经绘制了几个表格以查看是否可以为它建立直觉,但我一直无法并且无法在我查看的文档中找到此信息。
我将使用从一开始的索引——如果你想一起打字,你可以设置⎕IO。
轴规范中给出的尺寸将受到影响。也就是说,如果你包围第 n 个维度,排名将降低,因为结果的形状将是没有 n[=39= 的原始形状第 ] 个维度。
⍴a ← 2 3 4⍴⍬
2 3 4
⍴⊂[1]a
3 4
⍴⊂[2]a
2 4
⍴⊂[3]a
2 3
现在,第 n 个维度的数组将保留它们在保留维度上的位置,但作为标量包含(即 封闭 ) 它们,产生一个嵌套数组:
a ← 2 2 2⍴⍳8
a
1 2
3 4
5 6
7 8
⊂[1]a
┌→──┐ ┌→──┐
│1 5│ │2 6│
└───┘ └───┘
┌→──┐ ┌→──┐
│3 7│ │4 8│
└───┘ └───┘
What is the underlying algorithm that
⊂[axis]array
is using to split the array? I've drawn out several tables to see if I could build an intuition for it, but I've not been able to and I've not been able to find this information in the documentation I've looked at.
对于您的示例,一个简单的直觉可能是想象两张印有 table 的半透明纸。你把它们放在彼此后面,稍微倾斜。然后,想象一下,如果在他们面前放一个光源,他们身后的墙上会投射出什么。您的结果是每个单元格中有两个值的预计平坦 table。
I can imagine enclosing on the first axis to mean sub-slicing the array on it's depth, yielding [[0 1][2 3]] & [[4 5][6 7]] or I could see it meaning sub-slicing on columns, yielding [[0 2][4 6]] & [[1 3][5 7]]. But of course it doesn't do either. (
⊂[1]A
does the second,
它不仅仅是子切片 – 包含 returns 嵌套数组(简单标量除外)。我误解了你的符号,或者以下内容不清楚:
1 2 3
1 2 3
⍴1 2 3
3 ⍝ rank 1, i.e. a vector
≡⍴1 2 3
1 ⍝ depth 1, i.e. a non-nested array
⊂1 2 3
┌→────┐
│1 2 3│
└─────┘
⍴⊂1 2 3 ⍝ rank 0, i.e. a scalar
≡⊂1 2 3
2 ⍝ depth >1, i.e. a nested array
what operation would do the first?)
您可以围绕一组维度:
⊂[2 3]a
┌→──┐ ┌→──┐
↓1 2│ ↓5 6│
│3 4│ │7 8│
└───┘ └───┘
但是,如上所述 Z ← ⊂[X]R
、⍴⍴Z ←→ (⍴⍴R)-⍴⍴X
。