Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 构建第一个轴形状为“的条件图”;无”;在张量流中_Python_Tensorflow_Neural Network - Fatal编程技术网

Python 构建第一个轴形状为“的条件图”;无”;在张量流中

Python 构建第一个轴形状为“的条件图”;无”;在张量流中,python,tensorflow,neural-network,Python,Tensorflow,Neural Network,在图形构建阶段,假设张量x,这是一个神经网络的完全连接层 因此假设x的形状是(?,5)。我想在python中设置最后一列,如下所示: for i in range(x.shape[0]): if x[i,-1] < 0.5: x[i,-1] = 0.0 else: x[i,-1] = 1.0 当x的第一个维度是??这样时,我如何检查上面的内容 import tensorflow as tf import numpy as np a = t

在图形构建阶段,假设张量
x
,这是一个神经网络的完全连接层

因此假设
x
的形状是
(?,5)
。我想在python中设置最后一列,如下所示:

for i in range(x.shape[0]):
    if x[i,-1] < 0.5:
        x[i,-1] = 0.0
    else:
        x[i,-1] = 1.0
x
的第一个维度是

这样时,我如何检查上面的内容

import tensorflow as tf
import numpy as np

a = tf.placeholder(tf.int32, shape=[None, 5])

r, c = a.get_shape()
x_split = tf.split(1, c, a) # split a along axis 1
last_col = x_split[-1]


mask = tf.greater(last_col, tf.constant(6))
cond = tf.where(mask,
                tf.add(last_col, tf.constant(1)), # if true, add one
                tf.add(last_col, tf.constant(-1)))# if false, minus one

x_split = x_split[0:-1]
x_split.append(cond)
ans = tf.concat(1, x_split)


with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    arr = np.array([[1, 2, 3, 4, 5],
                    [6, 7, 8, 9, 10]])
    the_ans = sess.run(ans, feed_dict={a: arr})
'''
the_ans is 
[[ 1  2  3  4  4]
 [ 6  7  8  9 11]]
'''
像这样

import tensorflow as tf
import numpy as np

a = tf.placeholder(tf.int32, shape=[None, 5])

r, c = a.get_shape()
x_split = tf.split(1, c, a) # split a along axis 1
last_col = x_split[-1]


mask = tf.greater(last_col, tf.constant(6))
cond = tf.where(mask,
                tf.add(last_col, tf.constant(1)), # if true, add one
                tf.add(last_col, tf.constant(-1)))# if false, minus one

x_split = x_split[0:-1]
x_split.append(cond)
ans = tf.concat(1, x_split)


with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    arr = np.array([[1, 2, 3, 4, 5],
                    [6, 7, 8, 9, 10]])
    the_ans = sess.run(ans, feed_dict={a: arr})
'''
the_ans is 
[[ 1  2  3  4  4]
 [ 6  7  8  9 11]]
'''

非常感谢你的回答,这是我想要的:-)非常感谢你的回答,这是我想要的:-)