如何在tf.Variable中进行矩阵组合?

我有这两个矩阵,需要将它们组合起来,如下所示:

enter image description here

它们在代码中的表示如下:

matrix_a = tf.Variable(np.zeros(big_shape, dtype=np.float32))matrix_b = tf.Variable(np.zeros(small_shape, dtype=np.float32))  #在这里我需要将它们组合

我该如何做呢?

###################################################### EDITED

感谢@***,我编写了以下代码:

    shape = (batch_size, window_size, window_size, num_channels)    # 我们要优化的变量    modifier = tf.Variable(np.zeros(shape, dtype=np.float32))    mask = tf.zeros((batch_size, image_size, image_size, num_channels), tf.float32)    # 获取输入形状    modifier_shape = tf.shape(modifier)    mask_shape = tf.shape(mask)    # 生成索引网格    oo, ii, jj, kk = tf.meshgrid(tf.range(modifier_shape[0]), tf.range(modifier_shape[1]), tf.range(modifier_shape[2], modifier_shape[3]), indexing='ij')    # 移动索引    ii += y_window    jj += x_window    # 散布更新    mask_to_apply = tf.tensor_scatter_nd_update(mask, tf.stack([oo, ii, jj, kk], axis=-1), modifier)

但现在我遇到了这个错误:

ValueError: Requires start <= limit when delta > 0: 28/1 for 'range_2' (op: 'Range') with input shapes: [], [], [] and with computed input tensors: input[0] = <28>, input[1] = <1>, input[2] = <1>.

为什么会这样?


回答:

这是一种实现方法:

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注