NumCpp  1.0
A C++ implementation of the Python Numpy library
meshgrid.hpp
Go to the documentation of this file.
1 #pragma once
30 
31 #include "NumCpp/NdArray.hpp"
34 
35 #include <utility>
36 
37 namespace nc
38 {
39  //============================================================================
40  // Method Description:
54  template<typename dtype>
55  std::pair<NdArray<dtype>, NdArray<dtype> > meshgrid(const NdArray<dtype>& inICoords, const NdArray<dtype>& inJCoords)
56  {
58 
59  const uint32 numRows = inJCoords.size();
60  const uint32 numCols = inICoords.size();
61  auto returnArrayI = NdArray<dtype>(numRows, numCols);
62  auto returnArrayJ = NdArray<dtype>(numRows, numCols);
63 
64  // first the I array
65  for (uint32 row = 0; row < numRows; ++row)
66  {
67  for (uint32 col = 0; col < numCols; ++col)
68  {
69  returnArrayI(row, col) = inICoords[col];
70  }
71  }
72 
73  // then the I array
74  for (uint32 col = 0; col < numCols; ++col)
75  {
76  for (uint32 row = 0; row < numRows; ++row)
77  {
78  returnArrayJ(row, col) = inJCoords[row];
79  }
80  }
81 
82  return std::make_pair(returnArrayI, returnArrayJ);
83  }
84 
85  //============================================================================
86 // Method Description:
99  template<typename dtype>
100  std::pair<NdArray<dtype>, NdArray<dtype> > meshgrid(const Slice& inSlice1, const Slice& inSlice2)
101  {
102  return meshgrid(arange<dtype>(inSlice1), arange<dtype>(inSlice2));
103  }
104 
105 }
StaticAsserts.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:38
nc::NdArray< dtype >
nc::uint32
std::uint32_t uint32
Definition: Types.hpp:41
NdArray.hpp
nc::NdArray::size
size_type size() const noexcept
Definition: NdArrayCore.hpp:4310
nc::meshgrid
std::pair< NdArray< dtype >, NdArray< dtype > > meshgrid(const NdArray< dtype > &inICoords, const NdArray< dtype > &inJCoords)
Definition: meshgrid.hpp:55
nc
Definition: Coordinate.hpp:45
arange.hpp
nc::Slice
A Class for slicing into NdArrays.
Definition: Slice.hpp:44