-
-
Save lorenzoriano/5414671 to your computer and use it in GitHub Desktop.
C++ Analogous of Python linspace, returns a std::vector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <typename T> | |
std::vector<T> linspace(T a, T b, size_t N) { | |
T h = (b - a) / static_cast<T>(N-1); | |
std::vector<T> xs(N); | |
typename std::vector<T>::iterator x; | |
T val; | |
for (x = xs.begin(), val = a; x != xs.end(); ++x, val += h) | |
*x = val; | |
return xs; | |
} |
lagordon70
commented
Jul 14, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment