Assigning scalar elements

Scalar values of valid type can always get assigned to all left hand side element specifications:

  • single element addressed (trivial case, described here)
  • sequentially addressed ranges of elements (described here)
  • regulary addressed ranges of elements (described here)

The scalar value assigned will than replace all elements addressed as shown in the following example:

ILArray<double> A = ILMath.ones(4,3);
// A is now:
//(:,:)
// 1,00000   1,00000   1,00000
// 1,00000   1,00000   1,00000
// 1,00000   1,00000   1,00000
// 1,00000   1,00000   1,00000

// set elements of the last columns to 55
A[":;end"] = 55.0; 
// - or - 
A[null,2] = 55.0; 
      
// A is now:
//(:,:) 1e+001 * 
// 0,10000   0,10000   5,50000 
// 0,10000   0,10000   5,50000
// 0,10000   0,10000   5,50000 
// 0,10000   0,10000   5,50000 

In the next example we will assing the scalar value -333.3 to some elements by sequential indexing:

ILArray<double> A = ILMath.ones(4,3);
ILArray<int> ind = ILMath.toInt32(ILMath.rand(2,2)*12);
// A is now:
//(:,:)
// 1,00000   1,00000   1,00000
// 1,00000   1,00000   1,00000
// 1,00000   1,00000   1,00000
// 1,00000   1,00000   1,00000
// 
// ind (may) is now: 
//(:,:) 
//           3            8 
//          10            5 

// set random elements to -333.3
A[ind] = -333.3; 

// A is now: 
//(:,:) 1e+001 * 
//  0,10000    0,10000  -33,33000 
//  0,10000  -33,33000    5,50000 
//  0,10000    0,10000  -33,33000 
//-33,33000    0,10000    5,50000

Valid CSS! Valid XHTML 1.0 Transitional