小编use*_*614的帖子

为什么 tf.matmul(a,b, transpose_b=True) 有效,但 tf.matmul(a, tf.transpose(b)) 无效?

代码:

x = tf.constant([1.,2.,3.], shape = (3,2,4))
y = tf.constant([1.,2.,3.], shape = (3,21,4))
tf.matmul(x,y)                     # Doesn't work. 
tf.matmul(x,y,transpose_b = True)  # This works. Shape is (3,2,21)
tf.matmul(x,tf.transpose(y))       # Doesn't work.
Run Code Online (Sandbox Code Playgroud)

我想知道y里面变成了什么形状,tf.matmul(x,y,transpose_b = True)这样我就可以通过注意力来弄清楚 LSTM 内部到底发生了什么。

python linear-algebra matrix-multiplication deep-learning tensorflow

5
推荐指数
1
解决办法
3556
查看次数

在R中:如何将因子转换为列并使用其他列中的相应值填充这些列?

我有一个像这样组织的data.frame:

   id question input
1  11        1     6
2  12        1     7
3  13        1     5
4  14        2     5
5  15        2     6
6  16        3     4
7  17        4     5
8  18        4     5
9  19        4     4
10 20        5     3
Run Code Online (Sandbox Code Playgroud)

我需要将"问题"列变成一系列列(一个用于问题1,一个用于问题2,等等),这没关系 - 我已经在网上找到了答案.

但是,我还需要使用'input'中的相应值填充这些新列,因此生成的data.frame如下所示:

   id question input q1 q2 q3 q4 q5
1  11        1     6  6 NA NA NA NA
2  12        1     7  7 NA NA NA NA
3  13        1     5  5 NA …
Run Code Online (Sandbox Code Playgroud)

r reshape dataframe

-2
推荐指数
1
解决办法
483
查看次数