larray.LArray.prepend¶
-
LArray.prepend(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 : LArray
Array with compatible axes.
label : str, optional
Label for the new item in axis
Returns: LArray
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(X.sex, a.sum(X.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(X.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(X.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