NumCpp  1.0
A C++ implementation of the Python Numpy library
flip.hpp
Go to the documentation of this file.
1 #pragma once
30 
31 #include "NumCpp/NdArray.hpp"
33 #include "NumCpp/Core/Types.hpp"
34 
35 namespace nc
36 {
37  //============================================================================
38  // Method Description:
48  template<typename dtype>
49  NdArray<dtype> flip(const NdArray<dtype>& inArray, Axis inAxis = Axis::NONE)
50  {
51  switch (inAxis)
52  {
53  case Axis::NONE:
54  {
55  NdArray<dtype> returnArray(inArray);
56  stl_algorithms::reverse(returnArray.begin(), returnArray.end());
57  return returnArray;
58  }
59  case Axis::COL:
60  {
61  NdArray<dtype> returnArray(inArray);
62  for (uint32 row = 0; row < inArray.shape().rows; ++row)
63  {
64  stl_algorithms::reverse(returnArray.begin(row), returnArray.end(row));
65  }
66  return returnArray;
67  }
68  case Axis::ROW:
69  {
70  NdArray<dtype> returnArray = inArray.transpose();
71  for (uint32 row = 0; row < returnArray.shape().rows; ++row)
72  {
73  stl_algorithms::reverse(returnArray.begin(row), returnArray.end(row));
74  }
75  return returnArray.transpose();
76  }
77  default:
78  {
79  return NdArray<dtype>(0);
80  }
81  }
82  }
83 }
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4296
nc::Axis::NONE
@ NONE
nc::Axis::ROW
@ ROW
nc::NdArray::transpose
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4591
nc::NdArray< dtype >
nc::uint32
std::uint32_t uint32
Definition: Types.hpp:41
NdArray.hpp
nc::NdArray::end
iterator end() noexcept
Definition: NdArrayCore.hpp:1435
nc::stl_algorithms::reverse
void reverse(BidirIt first, BidirIt last) noexcept
Definition: StlAlgorithms.hpp:454
nc::Axis
Axis
Enum To describe an axis.
Definition: Types.hpp:47
nc::flip
NdArray< dtype > flip(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: flip.hpp:49
nc
Definition: Coordinate.hpp:45
StlAlgorithms.hpp
Types.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091
nc::Axis::COL
@ COL