简体   繁体   English

如何获取向量中大于0的值的索引?

[英]How to get indexes of values greater than 0 in vector?

I have a vector of size 1 000 000. I am increasing some values at some indexes.我有一个大小为 1 000 000 的向量。我在某些索引处增加了一些值。

How to get these indexes that were increased(that are not 0).如何获取这些增加的索引(不为 0)。 I do not want iterate through the whole vector, it will be too slow.我不想遍历整个向量,它会太慢。

For example, the input is 5 1 2 1 3 1 so the vector will look like this [0, 3, 1, 1, 0, 0, 0...] , the 5 is the size of the input.例如,输入是5 1 2 1 3 1所以向量看起来像这样[0, 3, 1, 1, 0, 0, 0...]5是输入的大小。 And I want to get from this vector only [3,1,1] .我只想从这个向量中得到[3,1,1]

Another example, the input is 6 9 1 1 1 3 1 so the vector will look like this [0, 4, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, ...] , the 6 is the size of the input.另一个例子,输入是6 9 1 1 1 3 1所以向量看起来像这样[0, 4, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, ...] , 6是输入的大小。 And I want to get from this vector only [4, 1, 1] .我只想从这个向量中得到[4, 1, 1]

I have a vector of size 1 000 000. I am increasing some values at some indexes.我有一个大小为 1 000 000 的向量。我在某些索引处增加了一些值。

How to get these indexes that were increased(that are not 0).如何获取这些增加的索引(不为 0)。 I do not want iterate through the whole vector, it will be too slow.我不想遍历整个向量,它会太慢。

For example, the input is 5 1 2 1 3 1 so the vector will look like this [0, 3, 1, 1, 0, 0, 0...] , the 5 is the size of the input.例如,输入是5 1 2 1 3 1所以向量看起来像这样[0, 3, 1, 1, 0, 0, 0...]5是输入的大小。 And I want to get from this vector only [3,1,1] .我只想从这个向量中得到[3,1,1]

Another example, the input is 6 9 1 1 1 3 1 so the vector will look like this [0, 4, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, ...] , the 6 is the size of the input.另一个例子,输入是6 9 1 1 1 3 1所以向量看起来像这样[0, 4, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, ...] , 6是输入的大小。 And I want to get from this vector only [4, 1, 1] .我只想从这个向量中得到[4, 1, 1]

I have a vector of size 1 000 000. I am increasing some values at some indexes.我有一个大小为 1 000 000 的向量。我在某些索引处增加了一些值。

How to get these indexes that were increased(that are not 0).如何获取这些增加的索引(不为 0)。 I do not want iterate through the whole vector, it will be too slow.我不想遍历整个向量,它会太慢。

For example, the input is 5 1 2 1 3 1 so the vector will look like this [0, 3, 1, 1, 0, 0, 0...] , the 5 is the size of the input.例如,输入是5 1 2 1 3 1所以向量看起来像这样[0, 3, 1, 1, 0, 0, 0...]5是输入的大小。 And I want to get from this vector only [3,1,1] .我只想从这个向量中得到[3,1,1]

Another example, the input is 6 9 1 1 1 3 1 so the vector will look like this [0, 4, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, ...] , the 6 is the size of the input.另一个例子,输入是6 9 1 1 1 3 1所以向量看起来像这样[0, 4, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, ...] , 6是输入的大小。 And I want to get from this vector only [4, 1, 1] .我只想从这个向量中得到[4, 1, 1]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM