Empty array: Difference between revisions
Jump to navigation
Jump to search
→Empty array shape
Miraheze>Marshall No edit summary |
Miraheze>Adám Brudzewsky |
||
Line 16: | Line 16: | ||
0 0 | 0 0 | ||
</source> | </source> | ||
{{Works in|[[Dyalog APL]]}} | {{Works in|[[Dyalog APL]], [[NARS2000]]}} | ||
The example above shows how an arithmetic rule can fail when using Rank with an empty array. For any positive integer <source lang=apl inline>n</source>, it's clear that <source lang=apl inline>(n,3) ≡ ⍴ ⍳⍤0 ⊢n⍴3</source> because each result cell is the array <source lang=apl inline>⍳3</source>. However, the empty array <source lang=apl inline>0⍴3</source> is indistinguishable from any other empty numeric array because it has shape <source lang=apl inline>,0</source> and prototype <source lang=apl inline>0</source>. This means Rank cannot determine the appropriate result shape. The Rank operator still attempts to find a sensible result shape: it executes the operand on a prototype cell obtained by reshaping the argument to the argument cell shape (here, the prototype cell is a scalar <source lang=apl inline>0</source>), and uses the resulting shape to determine the shape of its final result. In this case, this succeeds in finding the appropriate result rank but not the desired shape. | The example above shows how an arithmetic rule can fail when using Rank with an empty array. For any positive integer <source lang=apl inline>n</source>, it's clear that <source lang=apl inline>(n,3) ≡ ⍴ ⍳⍤0 ⊢n⍴3</source> because each result cell is the array <source lang=apl inline>⍳3</source>. However, the empty array <source lang=apl inline>0⍴3</source> is indistinguishable from any other empty numeric array because it has shape <source lang=apl inline>,0</source> and prototype <source lang=apl inline>0</source>. This means Rank cannot determine the appropriate result shape. The Rank operator still attempts to find a sensible result shape: it executes the operand on a prototype cell obtained by reshaping the argument to the argument cell shape (here, the prototype cell is a scalar <source lang=apl inline>0</source>), and uses the resulting shape to determine the shape of its final result. In this case, this succeeds in finding the appropriate result rank but not the desired shape. | ||