larray.Array.prepend¶
-
Array.
prepend
(self, axis, value, label=None)[source]¶ Adds an array before self along an axis.
The two arrays must have compatible axes.
Parameters: - axis : axis reference
Axis along which to prepend input array (value)
- value : scalar or Array
Scalar or array with compatible axes.
- label : str, optional
Label for the new item in axis
Returns: - Array
Array expanded with ‘value’ at the start of ‘axis’.
Examples
>>> a = ones('nat=BE,FO;sex=M,F') >>> a nat\sex M F BE 1.0 1.0 FO 1.0 1.0 >>> a.prepend('sex', a.sum('sex'), 'M+F') nat\sex M+F M F BE 2.0 1.0 1.0 FO 2.0 1.0 1.0 >>> a.prepend('nat', 2, 'Other') nat\sex M F Other 2.0 2.0 BE 1.0 1.0 FO 1.0 1.0 >>> b = zeros('type=type1,type2') >>> b type type1 type2 0.0 0.0 >>> a.prepend('sex', b, 'Other') nat sex\type type1 type2 BE Other 0.0 0.0 BE M 1.0 1.0 BE F 1.0 1.0 FO Other 0.0 0.0 FO M 1.0 1.0 FO F 1.0 1.0