StyleSubset =========== .. cpp:class:: numpy::StyleSubset numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use StyleSubset StyleSubset obj; // ... operations ... Constructors ------------ .. list-table:: :widths: 55 25 20 :header-rows: 1 * - Signature - Location - Example * - ``StyleSubset() = default`` - df_styler.h:47 - * - ``StyleSubset(const std::vector& cols, const std::vector& r)`` - df_styler.h:50 - Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``StyleSubset(const std::vector& cols) : columns(cols)`` - StyleSubset(const std::vector& cols) : - df_styler.h:48 - :ref:`View ` * - ``StyleSubset(const std::vector& r) : rows(r)`` - StyleSubset(const std::vector& r) : - df_styler.h:49 - :ref:`View ` Code Examples ------------- The following examples are extracted from the test suite. .. _example-stylesubset-columns-0: .. dropdown:: columns (np_test_4_all.cpp:22531) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 22521 :emphasize-lines: 11 mask.setElementAt({1, 3}, false); mask.setElementAt({2, 0}, false); mask.setElementAt({2, 1}, true); mask.setElementAt({2, 2}, true); mask.setElementAt({2, 3}, false); MaskedArray marr(data, mask); auto result = numpy::ma::compress_nd(marr, 1); // Should have 2 columns (columns 0 and 3) if (!(result.data().getShape().size() == 2)) { std::string description = std::string("test_compress_nd_2d_axis1():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.data().getShape().size() == 2)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(result.data().getShape()[0] == 3)) { std::string description = std::string("test_compress_nd_2d_axis1():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.data().getShape()[0] == 3)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } .. _example-stylesubset-rows-1: .. dropdown:: rows (np_test_2_all.cpp:4910) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 4900 :emphasize-lines: 11 namespace test_matrix { /** * Test basic matrix construction and properties */ void testMatrixBasics() { std::cout << "========= testMatrixBasics ======================="; // Test construction from dimensions numpy::Matrix m1(3, 3); assert_test(m1.rows() == 3, "Matrix rows"); assert_test(m1.cols() == 3, "Matrix cols"); assert_test(m1.isSquare(), "Matrix is square"); // Test construction from 2D vector std::vector> data = { {1, 2, 3}, {4, 5, 6} }; numpy::Matrix m2(data); assert_test(m2.rows() == 2, "Matrix from vector rows"); assert_test(m2.cols() == 3, "Matrix from vector cols"); assert_test(m2(0, 0) == 1, "Matrix element access"); assert_test(m2(1, 2) == 6, "Matrix element access");