“自我”的目的是什么

时间:2018-06-28 09:59:40

标签: python-3.x class self

我一直在学习使用python3的人工神经网络。我已经看到在类的方法中在赋值运算符(例如 _default_graph = self )之后使用 self 。我知道python中self的目的是指创建该类的特定对象,但我无法清楚地了解它与 self._default_graph 相同或具有不同目的的目的。同样,我也无法通过课堂方法清楚地理解回归自我的目的。

class Graph():

def __init__(self):

    self.operations = []
    self.placeholders = []
    self.variables = []

def set_as_default(self):
    """
    Sets this Graph instance as the Global Default Graph
    """
    global _default_graph
    _default_graph = self 

占位符的类:

class Placeholder():
"""
A placeholder is a node that needs to be provided a value for computing the output in the Graph.
"""

def __init__(self):

    self.output_nodes = []

    _default_graph.placeholders.append(self)

变量类:

class Variable():
"""
This variable is a changeable parameter of the Graph.
"""

def __init__(self, initial_value = None):

    self.value = initial_value
    self.output_nodes = []

    _default_graph.variables.append(self)

操作类别:

class Operation():
"""
An Operation is a node in a "Graph". TensorFlow will also use this concept of a Graph.

This Operation class will be inherited by other classes that actually compute the specific operation, such as adding or matrix multiplication.
"""

def __init__(self, input_nodes = []):
    """
    Intialize an Operation
    """
    self.input_nodes = input_nodes # The list of input nodes
    self.output_nodes = [] # List of nodes consuming this node's output

    for node in input_nodes:
        node.output_nodes.append(self)

    _default_graph.operations.append(self)

def compute(self):
    """ 
    This is a placeholder function. It will be overwritten by the actual specific operation that inherits from this class.

    """
    pass

基本图看起来像z = ax + b,a = 10且b = 1 z = 10x + 1 看起来像这样。

我可以通过这个吗?...预先谢谢

0 个答案:

没有答案