dask 2021.10.0

NotesParametersReturnsBackRef
insert(arr, obj, values, axis)

This docstring was copied from numpy.insert.

Some inconsistencies with the Dask version may exist.

Notes

Note that for higher dimensional inserts :None:None:`obj=0` behaves very different from :None:None:`obj=[0]` just like :None:None:`arr[:,0,:] = values` is different from :None:None:`arr[:,[0],:] = values`.

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

Support for multiple insertions when :None:None:`obj` is a single scalar or a sequence with one element (similar to calling insert multiple times).

values : array_like

Values to insert into :None:None:`arr`. If the type of values is different from that of :None:None:`arr`, values is converted to the type of :None:None:`arr`. values should be shaped so that arr[...,obj,...] = values is legal.

axis : int, optional

Axis along which to insert values . If :None:None:`axis` is None then :None:None:`arr` is flattened first.

Returns

out : ndarray

A copy of :None:None:`arr` with values inserted. Note that insert does not occur in-place: a new array is returned. If :None:None:`axis` is None, :None:None:`out` is a flattened array.

Insert values along the given axis before the given indices.

See Also

append

Append elements at the end of an array.

concatenate

Join a sequence of arrays along an existing axis.

delete

Delete elements from an array.

Examples

This example is valid syntax, but we were not able to check execution
>>> a = np.array([[1, 1], [2, 2], [3, 3]])  # doctest: +SKIP
... a # doctest: +SKIP array([[1, 1], [2, 2], [3, 3]])
This example is valid syntax, but we were not able to check execution
>>> np.insert(a, 1, 5)  # doctest: +SKIP
array([1, 5, 1, ..., 2, 3, 3])
This example is valid syntax, but we were not able to check execution
>>> np.insert(a, 1, 5, axis=1)  # doctest: +SKIP
array([[1, 5, 1],
       [2, 5, 2],
       [3, 5, 3]])

Difference between sequence and scalars:

This example is valid syntax, but we were not able to check execution
>>> np.insert(a, [1], [[1],[2],[3]], axis=1)  # doctest: +SKIP
array([[1, 1, 1],
       [2, 2, 2],
       [3, 3, 3]])
This example is valid syntax, but we were not able to check execution
>>> np.array_equal(np.insert(a, 1, [1, 2, 3], axis=1),  # doctest: +SKIP
...  np.insert(a, [1], [[1],[2],[3]], axis=1)) True
This example is valid syntax, but we were not able to check execution
>>> b = a.flatten()  # doctest: +SKIP
... b # doctest: +SKIP array([1, 1, 2, 2, 3, 3])
This example is valid syntax, but we were not able to check execution
>>> np.insert(b, [2, 2], [5, 6])  # doctest: +SKIP
array([1, 1, 5, ..., 2, 3, 3])
This example is valid syntax, but we were not able to check execution
>>> np.insert(b, slice(2, 4), [5, 6])  # doctest: +SKIP
array([1, 1, 5, ..., 2, 3, 3])
This example is valid syntax, but we were not able to check execution
>>> np.insert(b, [2, 2], [7.13, False]) # type casting  # doctest: +SKIP
array([1, 1, 7, ..., 2, 3, 3])
This example is valid syntax, but we were not able to check execution
>>> x = np.arange(8).reshape(2, 4)  # doctest: +SKIP
... idx = (1, 3) # doctest: +SKIP
... np.insert(x, idx, 999, axis=1) # doctest: +SKIP array([[ 0, 999, 1, 2, 999, 3], [ 4, 999, 5, 6, 999, 7]])
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

dask.array.routines.delete dask.array.routines.insert dask.array.routines.append

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /dask/array/routines.py#2277
type: <class 'function'>
Commit: