tensorflow:值错误:形状的级别必须为2,但对于“MatMul_1”来说却是级别4

2024-10-03 21:34:00 发布

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

我在下面的代码中遇到了一个错误,当我试图用稀疏矩阵乘以稠密矩阵时。在

import tensorflow as tf
import numpy as np

A = tf.sparse_placeholder(tf.float32)
B = tf.sparse_placeholder(tf.float32)

IsFoc = tf.placeholder(tf.float32, [None, 1])
IsFoc_Diag = tf.diag(IsFoc)

IsUnFoc = tf.placeholder(tf.float32, [None, 1])
IsUnFoc_Diag = tf.diag(IsUnFoc)

b = tf.matmul(IsFoc_Diag,IsUnFoc_Diag)
a = tf.matmul(IsFoc_Diag,tf.sparse_tensor_to_dense(A),a_is_sparse=False,b_is_sparse=True)

错误说明:

^{pr2}$

我知道也有类似的问题在讨论类似的错误,但是,我不知道这类错误的关键原因。在

错误只发生在a = tf.matmul(IsFoc_Diag,tf.sparse_tensor_to_dense(A),a_is_sparse=False,b_is_sparse=True)行上。我希望有人能回答我的问题。在

非常感谢!在


Tags: importnoneistfas错误矩阵placeholder