cppflow icon indicating copy to clipboard operation
cppflow copied to clipboard

How to iterate through a tensor?

Open B-Meg opened this issue 4 years ago • 2 comments

Hey follwing example:

I have a tensor that looks like this: (tensor: shape=[1 200 304], dtype=TF_FLOAT, data=... Now how can iterate through the tensor? With .get_data() I only get the data without the indices. But I want to do something like this: for (int row=0; row<maxRows; row++){ for (int col=0; col<macCol; col++){ Foo.Bar(my_cpp_tensor[row,col], row, col);}} How would I do that?

B-Meg avatar Aug 26 '21 12:08 B-Meg

The following example will give you a good idea of how to use a tensor.

https://github.com/serizba/cppflow/blob/883eb4c526979dae56f921571b1ab93df85a0a0d/examples/tensor/main.cpp#L28-L36

dskkato avatar Aug 26 '21 23:08 dskkato

It is not possible to use [row, col]. So you have to get the data from the tensor to a vector and index it flatten.

serizba avatar Mar 03 '22 15:03 serizba

Closing due to inactivity.

serizba avatar Sep 23 '22 11:09 serizba