Tensor.fillWith
- Tensor.fillWith(*args)
Automatically fills the tensor with v.
- Parameters:
v (
numberorlistofvaluesorpyagrum.Tensorornumpy.ndarray) – a value or a list/pyagrum.Tensor/ndarray containing the values to fill the Tensor with.mapping (
list|tuple|dict)
Warning
if
vis a list, the size of the list must be the size of the tensorif
vis a ref:pyagrum.Tensor, it must contain variables with exactly the same names and labels but not necessarily the same variables. IfIf the second argument
mappingis given,mappingexplains how to map the variables of the tensor source to the variables of the tensor destination.If
mappingis a sequence, the order follows the same order asdestination.names. Ifmappingis a dict, the keys are the names in the destination and the values are the names in the source.if
vis anumpy.ndarray, it must be C-contiguous, dtypefloat64, and its total size must equal the domain size. If it is N-D, its shape must equaltuple(reversed(self.shape)). Copies the data in a singlememcpy.
- Returns:
a reference to the modified tensor
- Return type:
- Raises:
pyagrum.SizeError – If v size’s does not matches the domain size.
pyagrum.ArgumentError – If anything wrong with the arguments.
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