NumCpp  2.6.2
A Templatized Header Only C++ Implementation of the Python NumPy Library
meshgrid.hpp
Go to the documentation of this file.
1 
28 #pragma once
29 
32 #include "NumCpp/NdArray.hpp"
33 
34 #include <utility>
35 
36 namespace nc
37 {
38  //============================================================================
39  // Method Description:
53  template<typename dtype>
54  std::pair<NdArray<dtype>, NdArray<dtype> > meshgrid(const NdArray<dtype>& inICoords, const NdArray<dtype>& inJCoords)
55  {
57 
58  const uint32 numRows = inJCoords.size();
59  const uint32 numCols = inICoords.size();
60  auto returnArrayI = NdArray<dtype>(numRows, numCols);
61  auto returnArrayJ = NdArray<dtype>(numRows, numCols);
62 
63  // first the I array
64  for (uint32 row = 0; row < numRows; ++row)
65  {
66  for (uint32 col = 0; col < numCols; ++col)
67  {
68  returnArrayI(row, col) = inICoords[col];
69  }
70  }
71 
72  // then the I array
73  for (uint32 col = 0; col < numCols; ++col)
74  {
75  for (uint32 row = 0; row < numRows; ++row)
76  {
77  returnArrayJ(row, col) = inJCoords[row];
78  }
79  }
80 
81  return std::make_pair(returnArrayI, returnArrayJ);
82  }
83 
84  //============================================================================
85 // Method Description:
98  template<typename dtype>
99  std::pair<NdArray<dtype>, NdArray<dtype> > meshgrid(const Slice& inSlice1, const Slice& inSlice2)
100  {
101  return meshgrid(arange<dtype>(inSlice1), arange<dtype>(inSlice2));
102  }
103 
104 } // namespace nc
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
size_type size() const noexcept
Definition: NdArrayCore.hpp:4497
A Class for slicing into NdArrays.
Definition: Slice.hpp:44
Definition: Coordinate.hpp:45
std::pair< NdArray< dtype >, NdArray< dtype > > meshgrid(const NdArray< dtype > &inICoords, const NdArray< dtype > &inJCoords)
Definition: meshgrid.hpp:54
std::uint32_t uint32
Definition: Types.hpp:40