qml.numpy.extract_tensors

class extract_tensors(x)[source]

Bases:

Iterate through an iterable, and extract any PennyLane tensors that appear.

Parameters

x (tensor or Sequence) – an input tensor or sequence

Yields

tensor – the next tensor in the sequence. If the input was a single tensor, than the tensor is yielded and the iterator completes.

Example

>>> from pennylane import numpy as np
>>> import numpy as onp
>>> iterator = np.extract_tensors([0.1, np.array(0.1), "string", onp.array(0.5)])
>>> list(iterator)
[tensor(0.1, requires_grad=True)]