NumCpp  2.18.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
take.hpp
Go to the documentation of this file.
1
28#pragma once
29
31#include "NumCpp/NdArray.hpp"
32
33namespace nc
34{
35 //============================================================================
36 // Method Description:
46 template<typename dtype, typename Indices, type_traits::ndarray_int_concept<Indices> = 0>
47 NdArray<dtype> take(const NdArray<dtype>& inArray, const Indices& inIndices, Axis inAxis = Axis::NONE)
48 {
49 switch (inAxis)
50 {
51 case Axis::NONE:
52 {
53 return inArray[inIndices];
54 }
55 case Axis::ROW:
56 {
57 return inArray(inIndices, inArray.cSlice());
58 }
59 case Axis::COL:
60 {
61 return inArray(inArray.rSlice(), inIndices);
62 }
63 default:
64 {
65 THROW_INVALID_ARGUMENT_ERROR("Unimplemented axis type.");
66 return {}; // get rid of compiler warning
67 }
68 }
69 }
70
71} // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition Error.hpp:37
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:135
Slice rSlice(index_type inStartIdx=0, size_type inStepSize=1) const
Definition NdArrayCore.hpp:1018
Slice cSlice(index_type inStartIdx=0, size_type inStepSize=1) const
Definition NdArrayCore.hpp:1004
Definition Cartesian.hpp:39
Axis
Enum To describe an axis.
Definition Enums.hpp:36
@ ROW
Definition Enums.hpp:38
@ COL
Definition Enums.hpp:39
@ NONE
Definition Enums.hpp:37
NdArray< dtype > take(const NdArray< dtype > &inArray, const Indices &inIndices, Axis inAxis=Axis::NONE)
Definition take.hpp:47