# how to generate tensorflow matrix with first of few columns as 1 and the rest as 0

54
November 13, 2019, at 5:20 PM

Given a list `len_list` of the number of ones for the vectors, e.g.:

``````



``````

where the shape of `len_list` now is `(4, 1)`

And given the number of columns of the vector, e.g. `vec_dim = 5`.

I'd like to generate a tensor with the first of few columns as 1 and the rest as 0. For example, a matrix with shape of `(4, 5)` as:

``````[1 0 0 0 0]
[1 1 1 0 0]
[1 1 0 0 0]
[1 0 0 0 0]
``````

How to do so?

I understand I could generate this matrix with iteration.

But in my case, the batch size is not set, i.e. the shape for `len_list` is `(None, 1)`, I have to feed the placeholder with batch size to fulfill this function. Thus, how could I generate a tensor with shape `(None, vec_dim)`???

POPULAR ONLINE

#### PHP XDebug on Docker Containers do not works in VS Code (Laravel and docker-compose) ### Win32COM code wont replace excel strings in a formula reference

This code copies the first sheet of an excel workbook that already has formulas into a new bookFor some reason, when you move the sheet, the formulas still reference the old book (in the example below-- Book1)

42 ### Python text_content() returns bound method

Can't figure out why this is returning as bound method HtmlMixintext_content, trying to create a web-scraper and display the data in a dataframe

55 ### Python Sum Second Element of Tuple by First Element

I have the following two lists in Python3:

47 ### Executing MapReduce MRJob code in Python and getting IndexError: list index out of range message

Well, I am trying the mrjob library and the code I wrote is not working properlyI looked at it and it seems fine from the little that I know about MapReduce library

17