21、TensorFlow教程--- XOR 实现

在本章中,我们将学习如何使用 TensorFlow 实现 XOR。在开始 TensorFlow 中的 XOR 实现之前,让我们先看一下 XOR 表的数值。这将帮助我们理解加密和解密过程。

XOR密码加密方法基本上用于加密难以使用暴力破解方法破解的数据,即通过生成与适当密钥匹配的随机加密密钥。

使用XOR密码的实现概念是定义一个XOR加密密钥,然后对用户尝试加密的指定字符串中的字符执行与此密钥的XOR操作。现在,我们将专注于使用TensorFlow进行XOR实现,如下所示 −

#Declaring necessary modules
import tensorflow as tf
import numpy as np
"""
A simple numpy implementation of a XOR gate to understand the backpropagation
algorithm
"""

x = tf.placeholder(tf.float64,shape = [4,2],name = "x")
#declaring a place holder for input x
y = tf.placeholder(tf.float64,shape = [4,1],name = "y")
#declaring a place holder for desired output y

m = np.shape(x)[0]#number of training examples
n = np.shape(x)[1]#number of features
hidden_s = 2

猜你喜欢

转载自blog.csdn.net/Knowledgebase/article/details/133459867
xor