init(concatenating:axis:dataType:)
Concatenate MLMultiArrays to form a new MLMultiArray.
Declaration
convenience init(concatenating multiArrays: [MLMultiArray], axis: Int, dataType: MLMultiArrayDataType)Parameters
- multiArrays:
Array of MLMultiArray instances to be concatenated.
- axis:
Axis index with which the concatenation will performed. The value is wrapped by the dimension of the axis. For example, -1 is the last axis.
- dataType:
The data type of the resultant MLMultiArray.
Discussion
All the source MLMultiArrays must have a same shape except the specified axis. The resultant MLMultiArray has the same shape as inputs except this axis, which dimension will be the sum of all the input dimensions of the axis.
For example,
// Swift
let A = try MLMultiArray(shape: [2, 3], dataType: .int32)
let B = try MLMultiArray(shape: [2, 2], dataType: .int32)
let C = MLMultiArray(concatenating: [A, B], axis: 1, dataType: .int32)
assert(C.shape == [2, 5])// Obj-C
MLMultiArray *A = [[MLMultiArray alloc] initWithShape:@[@2, @3] dataType:MLMultiArrayDataTypeInt32 error:NULL];
MLMultiArray *B = [[MLMultiArray alloc] initWithShape:@[@2, @2] dataType:MLMultiArrayDataTypeInt32 error:NULL];
MLMultiArray *C = [MLMultiArray multiArrayByConcatenatingMultiArrays:@[A, B] alongAxis:1 dataType:MLMultiArrayDataTypeInt32];
assert(C.shape == @[@2, @5])Numeric data will be up or down casted as needed.
The method raises NSInvalidArgumentException if the shapes of input multi arrays are not compatible for concatenation.