unfold
The unfold operator returns an n+1 dimensional result array based on an n-dimensional input array. The first n dimensions match the dimensions of the input array. The last dimension corresponds to the list of attributes from the input array. The cell values in the result array correspond to the values of the attributes in the original array.
Synopsis
unfold(array)
Summary
The unfold operator returns an n+1 dimensional result array based on an n-dimensional input array. The first n dimensions match the dimensions of the input array. The last dimension corresponds to the list of attributes from the input array. The cell values in the result array correspond to the values of the attributes in the original array.
The unfold operator rearranges data values from the original array; every data value from the original array is preserved. If the original array includes m attributes, the new dimension of the resulting array have values ranging from 0 to m-1. In the new dimension, the value 0 corresponds to the leftmost attribute of the original array and the value m-1 corresponds to the rightmost.
The result array includes one attribute which has the same name as the first attribute in the source array.
Limitations
Every attribute in the input array requires the same data type.
Example
Using the Operator
To demonstrate unfold operator, do the following:
Create an array by entering:
AFL% create array A <a:int64>[x=1:2; y=1:2];
Store values for the attribute a:
AFL% store(build(A, (sin(x) +y ) * 100), A); Â
The output is:{x,y} a {1,1} 184 {1,2} 284 {2,1} 190 {2,2} 290
Add a second attribute, z, using the apply operator, and store the result in array B:
AFL% store(apply(A, z, (x+y)*a), B);
The output is:{x,y} a,z {1,1} 184,368 {1,2} 284,852 {2,1} 190,570 {2,2} 290,1160
Unfold the example array, B, which creates a new attribute (unfold_2) with values in the range 0-1: 0 maps to the attribute a, and 1 maps to attribute z:
AFL% unfold(B);Â
The output is:{x,y,unfold_2} a {1,1,0} 184 {1,1,1} 368 {1,2,0} 284 {1,2,1} 852 {2,1,0} 190 {2,1,1} 570 {2,2,0} 290 {2,2,1} 1160
Remove the example arrays:
AFL% remove(A); remove(B);