Python 我该怎么办';对于循环';张量形状为(?,20)
我正在尝试这样做:Python 我该怎么办';对于循环';张量形状为(?,20),python,tensorflow,Python,Tensorflow,我正在尝试这样做: for i in range(int(linear.get_shape()[0])): for j in range(int(linear.get_shape()[1])): if linear[i][j]<0.5 and linear[i][j]>-0.5: linear[i][j]==0 我有一个错误: Traceback (most recent call last): File "L1_01.py", li
for i in range(int(linear.get_shape()[0])):
for j in range(int(linear.get_shape()[1])):
if linear[i][j]<0.5 and linear[i][j]>-0.5:
linear[i][j]==0
我有一个错误:
Traceback (most recent call last):
File "L1_01.py", line 52, in <module>
train_X_=model.fit_transform(train_X)[0]
File "/home/hjson/tmp/BRCA/libsdae/stacked_autoencoder.py", line 126, in fit_transform
self.fit(x)
File "/home/hjson/tmp/BRCA/libsdae/stacked_autoencoder.py", line 92, in fit
print_step=self.print_step, lambda_=self.lambda_, glscale=self.glscale)
File "/home/hjson/tmp/BRCA/libsdae/stacked_autoencoder.py", line 144, in run
tf.matmul(x, encode['weights']) + encode['biases'], activation)
File "/home/hjson/tmp/BRCA/libsdae/stacked_autoencoder.py", line 220, in activate
for i in range(int(linear.get_shape()[0])):
TypeError: __int__ returned non-int (type NoneType)
回溯(最近一次呼叫最后一次):
文件“L1_01.py”,第52行,在
train\ux\ux=模型。拟合变换(train\ux)[0]
文件“/home/hjson/tmp/BRCA/libsdae/stacked_autoencoder.py”,第126行,在fit_变换中
自我适应(x)
文件“/home/hjson/tmp/BRCA/libsdae/stacked_autoencoder.py”,第92行,合适
打印步骤=self.print步骤,lambda\ux=self.lambda\ux,glscale=self.glscale)
文件“/home/hjson/tmp/BRCA/libsdae/stacked_autoencoder.py”,第144行,运行中
tf.matmul(x,编码['weights'])+编码['biases'],激活)
文件“/home/hjson/tmp/BRCA/libsdae/stacked_autoencoder.py”,第220行,激活
对于范围内的i(int(linear.get_shape()[0]):
TypeError:\uuuuu int\uuuu返回的非int(类型NoneType)
我怎样才能解决这个问题 这可以通过基于所需范围创建遮罩并将遮罩应用于原始矩阵来实现。因此,如果矩阵为X,则需要:
tf.cast(
tf.logical_or(X >= 0.5, X <= -0.5),
X.dtype
) * X
tf.cast(
tf.logical_或(X>=0.5,X我建议你阅读一些关于TF的教程,因为你所做的事情的整个概念没有任何意义。无论如何,我的回答解释了你如何实现你想要的。谢谢你的建议。我刚刚学习了TF,仍然很困惑。谢谢你的评论。但我不明白为什么你乘以X,就得到了除TF之外的所有值我刚试过一些例子,我明白了。谢谢你抽出时间
tf.cast(
tf.logical_or(X >= 0.5, X <= -0.5),
X.dtype
) * X