1477

Expand Vector in Tensorflow and space elements with zeros

I would like to space vector elements from each others and fill it with zeros:

a = [1, 5, 7, ..., 3]

Space elements of a with two zeros:

b = [1, 0, 0, 5, 0, 0, 7, 0, 0, ... , 3, 0, 0]

The number of zeros that I space the elements with should be flexible.

What's the best way to do this on the Graph in Tensorflow?

Answer1:

Could you do it as explained in this post (second example of the accepted answer)?

Basically I would first create b as a a vector of zeros, then compute the indices which point into b for all values in a and then use the code from the linked post to assign the values of a to these indices.

Something like this maybe:

a = tf.constant(np.array([1, 3, 5, 7])) dim = a.get_shape()[0].value n = 2 b = tf.fill(dims=[dim*(n+1)], value=0.0) new_indices = np.array([i + i*n for i in range(0, dim)]) # now call referenced code with new_indices to update `b`

I'm not sure that this is the best way per se, but it would get the job done.

Recommend

  • Is it necessary to close session after tensorflow InteractiveSession()
  • tensorflow - softmax ignore negative labels (just like caffe) [duplicate]
  • Anaconda installation of Tensorflow fails with Debian 8 VirtualBox
  • Retrieving last value of LSTM sequence in Tensorflow
  • JavaFX ComboBox setItems triggers onAction event
  • How does MemberWiseClone create a new object with the cloned properties?
  • How to filter entities that are deleted using linq to entities
  • parallelize process in missForest package
  • Sql indexes vs full table scan
  • Change Divider Color Android DatePicker Dialog
  • C++ String tokenisation from 3D .obj files
  • Google OAuth2 for an web application hosted behind NAT (intranet server without public IP)
  • C++ Armadillo Access Triangular Matrix Elements
  • Furthest-point Voronoi diagram in Java
  • phpmailer - How to verify a sent email arrived at its destination
  • Getting errors while using neuralnet function
  • possible limitation of implode function in PHP
  • Ruby and class variables in inherit class
  • Insertion large number of Entities into SQL Server 2012 [duplicate]
  • Get the number 18437736874454810627
  • Most efficient way to move table rows from one table to another
  • How to delay loading a property with linq to sql external mapping?
  • formatting the colorbar ticklabels with SymLogNorm normalization in matplotlib
  • Android screen density dpi vs ppi
  • Date difference with leap year
  • How would I use PHP exceptions to define a redirect?
  • How to extract text from Word files using C#?
  • Jquery - Jquery Wysiwyg return html as a string
  • Arrays break string types in Julia
  • Comma separated Values
  • WPF Applying a trigger on binding failure
  • Error creating VM instance in Google Compute Engine
  • Free memory of cv::Mat loaded using FileStorage API
  • Hits per day in Google Big Query
  • how does django model after text[] in postgresql [duplicate]
  • Memory offsets in inline assembly
  • Java static initializers and reflection
  • need help with bizarre java.net.HttpURLConnection behavior
  • Turn off referential integrity in Derby? is it possible?
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize