Вы можете сделать это с помощью tenorflow
scaleValue = tf.placeholder("float32", 2)
b = tf.expand_dims(scaleValue, axis=1)
c = tf.constant([[1,0,0,0]], 'float32')
d = tf.matmul(b,c)
res = tf.reshape(d, shape=[-1])
with tf.Session() as sess:
print (sess.run([res], feed_dict={scaleValue: np.array([1,3])}))
выход
[array([1., 0., 0., 0., 3., 0., 0., 0.], dtype=float32)]
Решение с использованием заполнения
scaleValue = tf.placeholder("float32", 2)
a = tf.expand_dims(scaleValue, axis=1)
paddings = tf.constant([[0, 0,], [0, 3]])
b = tf.pad(a, paddings, "CONSTANT")
res = tf.reshape(b, shape=[-1])
with tf.Session() as sess:
print (sess.run([res], feed_dict={scaleValue: np.array([1,3])}))
Установите постоянный отступ в нужную форму
Где в paddings = tf.constant([[top, bottom,], [left, right]])
, top, bottom, left, right
представляет №: нулей в соответствующей позиции.