Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/library/tensor/basic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1144,9 +1144,9 @@ Indexing

Like NumPy, PyTensor distinguishes between *basic* and *advanced* indexing.
PyTensor fully supports basic indexing
(see `NumPy's indexing <http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html>`_)
(see `NumPy's indexing <https://numpy.org/doc/stable/user/basics.indexing.html>`_)
and `integer advanced indexing
<http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#integer>`_.
<https://numpy.org/doc/stable/user/basics.indexing.html#integer-array-indexing>`_.

Index-assignment is *not* supported. If you want to do something like ``a[5]
= b`` or ``a[5]+=b``, see :func:`pytensor.tensor.subtensor.set_subtensor` and
Expand Down
22 changes: 14 additions & 8 deletions pytensor/tensor/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1453,10 +1453,14 @@ def set_subtensor(x, y, inplace=False, tolerate_inplace_aliasing=False):

Examples
--------
To replicate the numpy expression "r[10:] = 5", type
>>> from pytensor.tensor import vector
>>> r = vector("r")
>>> new_r = set_subtensor(r[10:], 5)
To replicate the numpy expression ``r[10:] = 5``, type

.. code-block:: python

from pytensor.tensor import set_subtensor, vector

r = vector("r")
new_r = set_subtensor(r[10:], 5)

"""
return inc_subtensor(
Expand Down Expand Up @@ -1504,16 +1508,18 @@ def inc_subtensor(
--------
To replicate the expression ``r[10:] += 5``:

..code-block:: python
.. code-block:: python

from pytensor.tensor import ivector, inc_subtensor

r = ivector()
r = ivector("r")
new_r = inc_subtensor(r[10:], 5)

To replicate the expression ``r[[0, 1, 0]] += 5``:

..code-block:: python
.. code-block:: python

r = ivector()
r = ivector("r")
new_r = inc_subtensor(r[10:], 5, ignore_duplicates=True)

"""
Expand Down