Industrial Data Science
in C# and .NET:
Simple. Fast. Reliable.
 
 

ILNumerics - Technical Computing

Modern High Performance Tools for Technical

Computing and Visualization in Industry and Science

tgt

Reshaping Range Definitions

Reshaping Access – Reshaping with full /":" and end /"end".

Reshaping Access

If for a subarray definition fewer parameters are given than dimensions exist for the array, the last dimension specified gets a special meaning. Consider the example array of size [4,3,2]:

When addressing into this array by only specifying two dimensions, trailing dimension(s) will join together up to the last dimension specified. We might image this effect as an implicit array reshape. Out of the original array, the subarray is created from the following reshaped version (even if the reshape is not really done).

The third dimension is joined to the last specified dimension. Joining two dimensions means multiplying its lengths. So the resulting dimension is 3 * 2 = 6 elements in length. Therefore, the expression A[0,4] is valid and points to the element '17' at position [0,1,1]. The scheme generalizes well to the case, where only one dimension was specified, which corresponds to sequential indexing into the whole array.

Reshaping with full and end

The special keywords full and end can also be used in reshaping subarray creation. If used for the last dimension specified, the same reshaping scheme applies. In the consequence, end addresses the last element regarding the (imagined) reshaped version of the array.

full addresses all elements according to the corresponding dimension of the reshaped size:

The full keyword offers an intuitive way to actually create reshaped versions of an array. A[full,full] realizes the imagined reshaped array from the last example. A[full] creates a column vector with all elements lined up, which corresponds to the internal storage scheme known from Sequential Indexing. However, it is more efficient, to use the reshape() function to archieve the same result.