DataFrameEWM#
-
class numpy::DataFrameEWM#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use DataFrameEWM
DataFrameEWM obj;
// ... operations ...
Constructors#
Signature |
Location |
Example |
|---|---|---|
|
df_dataframe.h:5920 |
Statistics#
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
DataFrame |
df_dataframe.h:5929 |
Code Examples#
The following examples are extracted from the test suite.
mean (np_test_1_all.cpp:11714)
11704 // Create test array
11705 auto array = createInt32Array({ 2, 3 }, 0);
11706 array.setElementAt({ 0, 0 }, 1);
11707 array.setElementAt({ 0, 1 }, 2);
11708 array.setElementAt({ 0, 2 }, 3);
11709 array.setElementAt({ 1, 0 }, 4);
11710 array.setElementAt({ 1, 1 }, 5);
11711 array.setElementAt({ 1, 2 }, 6);
11712
11713 // Test mean without axis
11714 auto mean_all = mean(array);
11715 if (!(approx_equal(mean_all.getElementAt({ 0 }), 3.5, 1e-10))) {
11716 std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(mean_all.getElementAt({ 0 }), 3.5, 1e-10))";
11717 std::cout << std::string("[FAIL] ") + description << std::endl;
11718 throw std::runtime_error(description);
11719 }
11720 // std::cout << "[OK] mean (all elements) works correctly\n";
11721
11722 // Test mean along axis 0
11723 auto mean_axis0 = mean(array, 0);
11724 if (!(mean_axis0.getShape()[0] == 3)) {
std (np_test_1_all.cpp:11836)
11826 auto var_sample = var(array, std::nullopt, 1); // ddof=1 for sample variance
11827 double expected_sample_var = 1.25 * 4.0 / 3.0; // Bessel's correction
11828 if (!(approx_equal(var_sample.getElementAt({ 0 }), expected_sample_var, 1e-10))) {
11829 std::string description = std::string("testVarianceAndStandardDeviation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(var_sample.getElementAt({ 0 }), expected_sample_var, 1e-10))";
11830 std::cout << std::string("[FAIL] ") + description << std::endl;
11831 throw std::runtime_error(description);
11832 }
11833 // std::cout << "[OK] Sample variance works correctly\n";
11834
11835 // Test standard deviation
11836 auto std_result = numpy::std(array, std::nullopt, 0);
11837 if (!(approx_equal(std_result.getElementAt({ 0 }), std::sqrt(expected_var), 1e-10))) {
11838 std::string description = std::string("testVarianceAndStandardDeviation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(std_result.getElementAt({ 0 }), std::sqrt(expected_var), 1e-10))";
11839 std::cout << std::string("[FAIL] ") + description << std::endl;
11840 throw std::runtime_error(description);
11841 }
11842 // std::cout << "[OK] Standard deviation works correctly\n";
11843
11844 // Test along axis
11845 auto array2d = createFloat64Array({ 2, 2 }, 0);
11846 array2d.setElementAt({ 0, 0 }, 1.0);
var (np_test_1_all.cpp:11816)
11806 std::cout << "========= testVarianceAndStandardDeviation =======================";
11807
11808 // Create test array with known variance
11809 auto array = createFloat64Array({ 4 }, 0);
11810 array.setElementAt({ 0 }, 1.0);
11811 array.setElementAt({ 1 }, 2.0);
11812 array.setElementAt({ 2 }, 3.0);
11813 array.setElementAt({ 3 }, 4.0);
11814
11815 // Test variance (population)
11816 auto var_result = var(array, std::nullopt, 0); // ddof=0 for population variance
11817 double expected_var = 1.25; // Known variance for [1,2,3,4]
11818 if (!(approx_equal(var_result.getElementAt({ 0 }), expected_var, 1e-10))) {
11819 std::string description = std::string("testVarianceAndStandardDeviation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(var_result.getElementAt({ 0 }), expected_var, 1e-10))";
11820 std::cout << std::string("[FAIL] ") + description << std::endl;
11821 throw std::runtime_error(description);
11822 }
11823 // std::cout << "[OK] Population variance works correctly\n";
11824
11825 // Test variance (sample)
11826 auto var_sample = var(array, std::nullopt, 1); // ddof=1 for sample variance