MCPcopy Create free account
hub / github.com/ColdGrub1384/Pyto / insert

Function insert

site-packages/numpy/lib/function_base.py:4431–4634  ·  view source on GitHub ↗

Insert values along the given axis before the given indices. Parameters ---------- arr : array_like Input array. obj : int, slice or sequence of ints Object that defines the index or indices before which `values` is inserted. .. versionadded:: 1

(arr, obj, values, axis=None)

Source from the content-addressed store, hash-verified

4429
4430@array_function_dispatch(_insert_dispatcher)
4431def insert(arr, obj, values, axis=None):
4432 """
4433 Insert values along the given axis before the given indices.
4434
4435 Parameters
4436 ----------
4437 arr : array_like
4438 Input array.
4439 obj : int, slice or sequence of ints
4440 Object that defines the index or indices before which `values` is
4441 inserted.
4442
4443 .. versionadded:: 1.8.0
4444
4445 Support for multiple insertions when `obj` is a single scalar or a
4446 sequence with one element (similar to calling insert multiple
4447 times).
4448 values : array_like
4449 Values to insert into `arr`. If the type of `values` is different
4450 from that of `arr`, `values` is converted to the type of `arr`.
4451 `values` should be shaped so that ``arr[...,obj,...] = values``
4452 is legal.
4453 axis : int, optional
4454 Axis along which to insert `values`. If `axis` is None then `arr`
4455 is flattened first.
4456
4457 Returns
4458 -------
4459 out : ndarray
4460 A copy of `arr` with `values` inserted. Note that `insert`
4461 does not occur in-place: a new array is returned. If
4462 `axis` is None, `out` is a flattened array.
4463
4464 See Also
4465 --------
4466 append : Append elements at the end of an array.
4467 concatenate : Join a sequence of arrays along an existing axis.
4468 delete : Delete elements from an array.
4469
4470 Notes
4471 -----
4472 Note that for higher dimensional inserts `obj=0` behaves very different
4473 from `obj=[0]` just like `arr[:,0,:] = values` is different from
4474 `arr[:,[0],:] = values`.
4475
4476 Examples
4477 --------
4478 >>> a = np.array([[1, 1], [2, 2], [3, 3]])
4479 >>> a
4480 array([[1, 1],
4481 [2, 2],
4482 [3, 3]])
4483 >>> np.insert(a, 1, 5)
4484 array([1, 5, 1, 2, 2, 3, 3])
4485 >>> np.insert(a, 1, 5, axis=1)
4486 array([[1, 5, 1],
4487 [2, 5, 2],
4488 [3, 5, 3]])

Callers 1

insert_uniqueMethod · 0.50

Calls 13

asarrayFunction · 0.90
onesFunction · 0.90
wrapFunction · 0.50
arrayFunction · 0.50
emptyFunction · 0.50
ravelMethod · 0.45
warnMethod · 0.45
copyMethod · 0.45
indicesMethod · 0.45
arrayMethod · 0.45
astypeMethod · 0.45
itemMethod · 0.45

Tested by

no test coverage detected