Tensor.fillWith

Tensor.fillWith(*args)

Automatically fills the tensor with v.

Parameters:
  • v (number or list of values or pyagrum.Tensor or numpy.ndarray) – a value or a list/pyagrum.Tensor/ndarray containing the values to fill the Tensor with.

  • mapping (list|tuple|dict)

Warning

  • if v is a list, the size of the list must be the size of the tensor

  • if v is a ref:pyagrum.Tensor, it must contain variables with exactly the same names and labels but not necessarily the same variables. If

  • If the second argument mapping is given, mapping explains how to map the variables of the tensor source to the variables of the tensor destination.

  • If mapping is a sequence, the order follows the same order as destination.names. If mapping is a dict, the keys are the names in the destination and the values are the names in the source.

  • if v is a numpy.ndarray, it must be C-contiguous, dtype float64, and its total size must equal the domain size. If it is N-D, its shape must equal tuple(reversed(self.shape)). Copies the data in a single memcpy.

Returns:

a reference to the modified tensor

Return type:

pyagrum.Tensor

Raises:

Example

import pyagrum as gum

a, b = gum.LabelizedVariable("a", "a", 2), gum.LabelizedVariable("b", "b", 3)
p = gum.Tensor().add(a).add(b)
p.fillWith(0.5).sum()
# 3.0
p.fillWith([1, 2, 3, 4, 5, 6])  # the first variable (a) varies fastest
print(p)
#
#       ║  a                │
# b     ║0        │1        │
# ──────║─────────│─────────│
# 0     ║ 1.0000  │ 2.0000  │
# 1     ║ 3.0000  │ 4.0000  │
# 2     ║ 5.0000  │ 6.0000  │

Class

Tensor