I use the gnu science library (GSL). Say I have gsl_vector : 7 0 -6 5 8 0 10 -2
This is a vector containing positive numbers, negative numbers, and zeros as elements.
I want to count the number of non-zero elements or zero elements in this gsl_vector . I know that there is a function called count_if for C ++ Vector. But I look through gsl_vector.h and gsl_blas.h , there is no function equal to this. I can go through at least all the elements, evaluate them, although gsl_vector_get() , and then ask the if question.
int counter = 0; for(int i = 0;i<length_of_the_gsl_vector;++i){ if(fabs(gsl_vector_get(y,i))<0.5) ++counter; } return counter;
But I was wondering for almost the whole day whether there is such a feature already in GSL, which is much more efficient.
Or maybe there is a count_if function for gsl_array ?
source share