import numpy as np转成c++代码
时间: 2023-07-28 19:06:35 浏览: 78
C++中没有像Python中的NumPy库,但是可以使用STL库中的vector来实现类似的功能。下面是一个简单的示例,将Python中的numpy数组转换为C++中的vector:
Python代码:
```python
import numpy as np
a = np.array([1, 2, 3])
b = np.array([[1, 2], [3, 4]])
print(a)
print(b)
```
C++代码:
```c++
#include <iostream>
#include <vector>
int main()
{
std::vector<int> a = {1, 2, 3};
std::vector<std::vector<int>> b = {{1, 2}, {3, 4}};
for (int i = 0; i < a.size(); i++)
{
std::cout << a[i] << " ";
}
std::cout << std::endl;
for (int i = 0; i < b.size(); i++)
{
for (int j = 0; j < b[i].size(); j++)
{
std::cout << b[i][j] << " ";
}
std::cout << std::endl;
}
return 0;
}
```
输出:
```
1 2 3
1 2
3 4
```