serizba / cppflow

Run TensorFlow models in C++ without installation and without Bazel
https://serizba.github.io/cppflow/
MIT License
779 stars 177 forks source link

How to create a two dimension tensor like (1000,5) (row,col) #189

Closed fiveriddle closed 1 year ago

fiveriddle commented 2 years ago

I don't know whether I'm wrong or not, it seems that the cppflow::fill and cppflow::tensor can only support one dimension tensor in the example. If I'm wrong, could you please tell me where to or how to generate a 2d tensor like (1000,5) (row,col) and pass it into the model? Many thanks!

yochananscharf commented 2 years ago

@fiverriddle, if you would like to initialize a tensor with all elements having the same value, use the following: float val = 1.0; cppflow::tensor tnsr = cppflow::fill({ 1000, 5 }, val); If you would like to initialize a tensor with various values, do the the following: Fill a vector (1d) with the values. Then initialize the tensor with the required shape. std::vector<float> vals(1000*5); cppflow::tensor tnsr = cppflow::tensor(vals, { 1000, 5 });

serizba commented 1 year ago

Closing due to inactivity.