存储2D阵列需要哪个STL容器? [英] which STL container do I need for storing a 2D-array?
问题描述
我正在从文件中读取一些双精度值。这是一个2D阵列:
1 2 3 4 5 6 7
-------------
1 3.2
2 0 2.1
3 9.3
4
5 4.5等等等。
6
我正在查看我的书并且无法弄清楚什么是最好用的。我想b
我认为我不需要随机访问迭代器。所以我可以选择:
vector,list,deque,set,multiset,map和multimap ...
读完所有数字之后,我想找到那些位于上百分位数组中的那些,我认为它被称为(那些最高价格的那两个数字中的10%)。
那么我可能需要这样的东西:
iter = find(array.begin(),array.end(),( 10% - 最高数量))
嗯。然后,不,这似乎不对...我有几个例子
用于在我的书中存储1D阵列。我不认为我有任何用于存储的数据,而且我有点困惑。
有人能推动我朝着正确的方向前进吗? br $>
最好的问候
Martin J?rgensen
-
------- -------------------------------------------------- ------------------
Martin J?rgensen的家 - http://www.martinjoergensen.dk
Martin J?rgensen写道:
有人能把我推向正确的方向吗?
你可能想看一下boost multi_array
Martin J?rgensen写道:
< blockquote class =post_quotes>
我正在从文件中读取一些双精度值。这是一个2D阵列:
我正在查看我的书并且无法弄清楚什么是最好用的。
std :: vector< std :: vector< float将直接完成工作。 (你会
甚至可以使用[] []双数组语法)。如果数组可能非常大且稀疏(即大多数为零),你可能要考虑使用
std :: map< float>, x和y索引作为关键。那将是更多的工作,但是可以节省(可能,并且仅在这种特殊情况下)大量内存。
我有阅读所有数字,我想找到那些位于上百分之10百分位数组中的那些,我认为它被称为(那些
数字的10%)这是最高的)。
如果你想使用标准算法,那么使用上面的std :: map方法可能会更容易
:它会是使用
向量的向量更加繁琐。
hth,
Tom
Martin J?rgensen写道:
我在读文件中的多个double值。这是一个2D阵列:
1 2 3 4 5 6 7
-------------
1 3.2
2 0 2.1
3 9.3
4
5 4.5等等等。
6
我正在查看我的书并且无法弄清楚什么是最好用的。我想b
我认为我不需要随机访问迭代器。所以我可以选择:
vector,list,deque,set,multiset,map和multimap ...
读完所有数字之后,我想找到那些位于上百分位数组中的那些,我认为它被称为(那些最高价格的那两个数字中的10%)。
那么我可能需要这样的东西:
iter = find(array.begin(),array.end(),( 10% - 最高数量))
嗯。然后,不,这似乎不对...我有几个例子
用于在我的书中存储1D阵列。我不认为我有任何用于存储的数据,而且我有点困惑。
有人能推动我朝着正确的方向前进吗?
我将使用1D阵列模拟2D阵列,即。一个std :: vector。
比如说,你可以使用
42元素1D阵列而不是6x7 2D阵列。所有你需要的将是一种转换方式
row&要使用两个
简单函数返回索引的列,我会让你自己弄明白。
HTH,
- J.
Hi,
I''m reading a number of double values from a file. It''s a 2D-array:
1 2 3 4 5 6 7
-------------
1 3.2
2 0 2.1
3 9.3
4
5 4.5 etc.etc.
6
I''m looking in my book and can''t figure out what is the best to use. I
don''t think I need a random access iterator. So I can choose among:
vector, list, deque, set, multiset, map and multimap...
After I have read in all the numbers, I want to find those that are in
the upper 10 percentile group, I think it''s called (those 10% of the
numbers that are highest).
So then I would probably need something like:
iter = find(array.begin(), array.end(), (10%-highest-number))
hmm. Then again, no, that seems not right... I have a couple of examples
for storing 1D-arrays in my book. I don''t think I have any for storing
2D-arrays and am a bit confused.
Can anyone push me in the right direction?
Best regards
Martin J?rgensen
--
---------------------------------------------------------------------------
Home of Martin J?rgensen - http://www.martinjoergensen.dk
Martin J?rgensen wrote:
Can anyone push me in the right direction?You may want to look at boost multi_array
Martin J?rgensen wrote:Hi,
I''m reading a number of double values from a file. It''s a 2D-array:
I''m looking in my book and can''t figure out what is the best to use.std::vector<std::vector <float will do the job straightforwardly. (You''ll
even be able to use [][] double-array syntax). If the array is likely to be very
big and sparse (ie, mostly zeros), you might want to consider using a
std::map<float>, with the x and y indices as the key. That would be more work,
but could save (potentially, and only in this particular situation) lots of memory.
After I have read in all the numbers, I want to find those that are in
the upper 10 percentile group, I think it''s called (those 10% of the
numbers that are highest).If you wanted to use standard algorithms, then this would probably be easier
with the std::map method above: it would be much more fiddly with a vector of
vectors.
hth,
Tom
Martin J?rgensen wrote:Hi,
I''m reading a number of double values from a file. It''s a 2D-array:
1 2 3 4 5 6 7
-------------
1 3.2
2 0 2.1
3 9.3
4
5 4.5 etc.etc.
6
I''m looking in my book and can''t figure out what is the best to use. I
don''t think I need a random access iterator. So I can choose among:
vector, list, deque, set, multiset, map and multimap...
After I have read in all the numbers, I want to find those that are in
the upper 10 percentile group, I think it''s called (those 10% of the
numbers that are highest).
So then I would probably need something like:
iter = find(array.begin(), array.end(), (10%-highest-number))
hmm. Then again, no, that seems not right... I have a couple of examples
for storing 1D-arrays in my book. I don''t think I have any for storing
2D-arrays and am a bit confused.
Can anyone push me in the right direction?I''d emulate the 2D-array using a 1D-array, ie. a std::vector.
Say, instead of having a 6x7 2D-array you may as well use a
42-element 1D-array. All you''d need would be a way to convert
row & column to index and the other way back using two
simple functions that I''ll let you figure out yourself.
HTH,
- J.
这篇关于存储2D阵列需要哪个STL容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!