张量形状为(?)时,我该怎么做“forloop”?,20)

2024-05-12 20:49:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在努力做到:

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

其中“线性”是:

^{pr2}$

我有个错误:

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)

我怎样才能解决这个问题呢。?在


Tags: inpyselfhomelinetmpfitfile
1条回答
网友
1楼 · 发布于 2024-05-12 20:49:38

这可以通过基于所需范围创建遮罩并将遮罩应用于原始矩阵来实现。如果矩阵是X,则需要:

tf.cast(
    tf.logical_or(X >= 0.5, X <= -0.5),
    X.dtype
) * X

相关问题 更多 >