Slicing a tensor by using indices in Tensorflow

2020-02-26 08:15发布

问题:

Basically I have a 2d array and I want to do this nice numpy-like thing

noise_spec[:rows,:cols]

in Tensorflow. Here rows and cols are just two integers.

回答1:

Indeed, TensorFlow now has better support for slicing, so you can use the exact same syntax as NumPy:

result = noise_spec[:rows, :cols]


回答2:

found out, it's

tf.slice(noise_spec, [0,0],[rows, cols])