NumCpp  2.7.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
meshgrid.hpp
Go to the documentation of this file.
1 #pragma once
29 
32 #include "NumCpp/NdArray.hpp"
33 
34 #include <utility>
35 
36 namespace nc
37 {
38  //============================================================================
39  // Method Description:
52  template<typename dtype>
53  std::pair<NdArray<dtype>, NdArray<dtype> > meshgrid(const NdArray<dtype>& inICoords, const NdArray<dtype>& inJCoords)
54  {
56 
57  const uint32 numRows = inJCoords.size();
58  const uint32 numCols = inICoords.size();
59  auto returnArrayI = NdArray<dtype>(numRows, numCols);
60  auto returnArrayJ = NdArray<dtype>(numRows, numCols);
61 
62  // first the I array
63  for (uint32 row = 0; row < numRows; ++row)
64  {
65  for (uint32 col = 0; col < numCols; ++col)
66  {
67  returnArrayI(row, col) = inICoords[col];
68  }
69  }
70 
71  // then the I array
72  for (uint32 col = 0; col < numCols; ++col)
73  {
74  for (uint32 row = 0; row < numRows; ++row)
75  {
76  returnArrayJ(row, col) = inJCoords[row];
77  }
78  }
79 
80  return std::make_pair(returnArrayI, returnArrayJ);
81  }
82 
83  //============================================================================
84  // Method Description:
96  template<typename dtype>
97  std::pair<NdArray<dtype>, NdArray<dtype> > meshgrid(const Slice& inSlice1, const Slice& inSlice2)
98  {
99  return meshgrid(arange<dtype>(inSlice1), arange<dtype>(inSlice2));
100  }
101 
102 } // 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:4296
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:53
std::uint32_t uint32
Definition: Types.hpp:40