简体   繁体   English

如何确定C ++中的向量维?

[英]How to determine the vector dimension in C++?

In python, I got a list 'quad_list = ((len(D),4,2))' , and 'len(D)' is a 2 dimension list something like ' [[0,1,2,3],[1,2,3,4],[3,4,5,6]]' . 在python中,我得到了一个列表'quad_list = ((len(D),4,2))' ,而'len(D)'是一个二维列表,类似于' [[0,1,2,3],[1,2,3,4],[3,4,5,6]]' Then if I want a same list in C++, that 'quad_list' going to be 'std::vector<std::vector<std::vector<int>>> quad_list(D.size(),4,2)' ? 然后,如果我想在C ++中使用相同的列表,则该'quad_list'将为'std::vector<std::vector<std::vector<int>>> quad_list(D.size(),4,2)' so it is a 3 dimension vector, and what if I wanna insert some value to the vector, or just do something like 'for i, j in zip(D, range(len(D))):' this python code in C++.... how to traversing the list in C++... 所以它是一个3维向量,如果我想在向量中插入一些值,或者只是做一些类似'for i, j in zip(D, range(len(D))):'事情,例如'for i, j in zip(D, range(len(D))):' C ++中'for i, j in zip(D, range(len(D))):'此python代码....如何在C ++中遍历列表...

I think if i wanna traversing the three dimension vector in C++, it as same as print, so it should be three level loop..and like 我想如果我想在C ++中遍历三维矢量,它与打印一样,因此应该是三级循环。

for(int i; i < vector...emmmmmm; i++)
{
    for(int j; j< vector.....emmmm; j++)
    {
        for(int k; k < vector......; k++)
        {
            ....
        }
    }
}

have no idea...sorry 不知道...抱歉

std::vector<std::vector<double>> D = region_group(region_list);
int lend = D.size();
std::vector<int> N(2, 0);
std::vector<std::vector<int>> qua(4, N);
std::vector<std::vector<std::vector<int>>> quad_list(lend, qua);//quad_list((len(D),4,2))
std::vector<int> S(4, 0);
std::vector<std::vector<int>>score_list(lend, S); //score_list = np.zeros((len(D), 4))

here for the code python for group,g_th in zip(D,range(len(D))): 这是python for group,g_th in zip(D,range(len(D))):的代码python for group,g_th in zip(D,range(len(D))):

Please give me some hints about the operation of high dimension vector in C++. 请给我一些有关C ++中高维向量的操作的提示。

If you have access to boost and C++17 , it's very similar to python 如果您可以使用boostC ++ 17 ,则它与python非常相似

for i, e in enumerate(C): # more pythonic than zip(range(len(C)), C)
    ...

Becomes 成为

using boost::adaptors::index;
for (auto [i, e] : index(C))
{
    ...
}

If you really want to have something similar to zip(C, range(len(C))) 如果您真的想要类似zip(C, range(len(C)))

for (auto [i, e] : boost::combine(boost::irange(C.size()), C))

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

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