Rate this Page

ParameterList#

classtorch.nn.ParameterList(values=None)[source]#

Holds parameters in a list.

ParameterList can be used like a regular Pythonlist, but Tensors that areParameter are properly registered,and will be visible by allModule methods.

Note that the constructor, assigning an element of the list, theappend() method and theextend()method will convert anyTensor intoParameter.

Parameters:

parameters (iterable,optional) – an iterable of elements to add to the list.

Example:

classMyModule(nn.Module):def__init__(self)->None:super().__init__()self.params=nn.ParameterList([nn.Parameter(torch.randn(10,10))foriinrange(10)])defforward(self,x):# ParameterList can act as an iterable, or be indexed using intsfori,pinenumerate(self.params):x=self.params[i//2].mm(x)+p.mm(x)returnx
append(value)[source]#

Append a given value at the end of the list.

Parameters:

value (Any) – value to append

Return type:

Self

extend(values)[source]#

Append values from a Python iterable to the end of the list.

Parameters:

values (iterable) – iterable of values to append

Return type:

Self

extra_repr()[source]#

Return the extra representation of the module.

Return type:

str