Alrott SlimRG Asked:2022-05-10 03:09:02 +0800 CST2022-05-10 03:09:02 +0800 CST 2022-05-10 03:09:02 +0800 CST qt c++中Python的numpy.linspace的类比 772 实际上,Python中有一个命令: x = np.linspace(0, l, N + 1) 如何在 Qt\C++ 中重写它? python 1 个回答 Voted Best Answer KoVadim 2022-05-10T04:24:40+08:002022-05-10T04:24:40+08:00 这样的功能很容易写在“膝盖上”。某处如此 #include <iostream> #include <vector> std::vector<double> linspace(double start, double end, int count) { std::vector<double> r; r.reserve(count); double step = (end - start) / (count-1); for (int i = 0; i < count ; i++) { r.push_back(start + i * step); } return r; } int main() { auto v = linspace(0,1,11); for (auto a : v) { std::cout << a << '\n'; } }
这样的功能很容易写在“膝盖上”。某处如此