Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Analyze the extraction and assignment of tensors in tensorflow

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "analyzing the extraction and assignment of tensors in tensorflow". In the daily operation, I believe that many people have doubts in analyzing the extraction and assignment of tensors in tensorflow. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "analyzing the extraction and assignment of tensors in tensorflow". Next, please follow the editor to study!

Tf.gather and gather_nd collect values from params, and tf.scatter_nd and tf.scatter_nd_update update a tensor with updates. Strictly speaking, tf.gather_nd and tf.scatter_nd_update are inverse operations of each other.

Knowing the position of the value, extract the value from the tensor: tf.gather, tf.gather_nd

Each element (scalar) of tf.gather indices is the index of an axis in params, and the last order of indices in tf.gather_nd corresponds to the index value.

Tf.gather function

Function prototype

Gather (params, indices, validate_indices=None, name=None, axis=0)

Params is the tensor to find, indices is the index (int32 or int64) to find the value, axis is the search axis, and name is the operation name.

If indices is a scalar

If indices is a vector

If indices is a higher order tensor

Return value:

This function returns the same type of value as params. The specific value is collected from params and has the shape of

Tf.gather_nd function

Function prototype

Gather_nd (params, indices, name=None)

Indices is a tensor of order K, which contains the index value of order 1 of Kmuri. Its last order is the index, and the last order dimension must be less than or equal to the rank of params. When the dimension of the last order of indices is equal to the rank of params, we get some elements of params; when the dimension of the last order of indices is less than the rank of params, we get the slice of params.

The shape of the output tensor is spliced by the K1 order of indices and the shape indexed by params, as shown below

Indices.shape [:-1] + params.shape [indices.shape [- 1]:]

Parameters:

Params: the tensor collected.

Indices: index tensor. Must be one of the following types: int32,int64.

Name: the name of the operation (optional).

Return value:

This function returns a tensor. Has the same type as params. Tensor values are collected from the index given by indices and have the following shape:

Given the position of assignment, assign values to tensor: tf.scatter_nd, tf.scatter_nd_update

Tf.scatter_nd assigns zero tensors and tf.scatter_nd_update assigns existing variable tensors.

Tf.scatter_nd function scatter_nd (indices, updates, shape, name=None)

Create a zero tensor of the shape shape and assign the updates to the location specified by indices.

Indices is an integer tensor, and the innermost dimension corresponds to the index.

Indices.shape [- 1]

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report