larray.LArray.insert¶
-
LArray.insert(value, before=None, after=None, pos=None, axis=None, label=None)[source]¶ Inserts value in array along an axis.
Parameters: value : scalar or LArray
Value to insert. If an LArray, it must have compatible axes. If value already has the axis along which it is inserted, label should not be used.
before : scalar or Group
Label or group before which to insert value.
after : scalar or Group
Label or group after which to insert value.
pos : int
Index before which to insert value.
axis : axis reference (int, str or Axis), optional
Axis in which to insert value. This is only required when using pos or when before or after are ambiguous labels.
label : str, optional
Label for the new item in axis.
Returns: LArray
Array with value inserted along axis. The dtype of the returned array will be the “closest” type which can hold both the array values and the inserted values without loss of information. For example, when mixing numeric and string types, the dtype will be object.
Examples
>>> arr1 = ndtest((2, 3)) >>> arr1 a\b b0 b1 b2 a0 0 1 2 a1 3 4 5 >>> arr1.insert(42, before='b1', label='b0.5') a\b b0 b0.5 b1 b2 a0 0 42 1 2 a1 3 42 4 5 >>> arr2 = ndtest(2) >>> arr2 a a0 a1 0 1 >>> arr1.insert(arr2, after='b0', label='b0.5') a\b b0 b0.5 b1 b2 a0 0 0 1 2 a1 3 1 4 5 >>> arr1.insert(42, axis='b', pos=1, label='b0.5') a\b b0 b0.5 b1 b2 a0 0 42 1 2 a1 3 42 4 5 >>> arr1.insert(42, before=X.b.i[1], label='b0.5') a\b b0 b0.5 b1 b2 a0 0 42 1 2 a1 3 42 4 5
insert an array which already has the axis
>>> arr3 = ndrange('a=a0,a1;b=b0.1,b0.2') + 42 >>> arr3 a\b b0.1 b0.2 a0 42 43 a1 44 45 >>> arr1.insert(arr3, before='b1') a\b b0 b0.1 b0.2 b1 b2 a0 0 42 43 1 2 a1 3 44 45 4 5