NumCpp
2.4.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
column_stack.hpp
Go to the documentation of this file.
1
#pragma once
29
30
#include "
NumCpp/Core/Internal/Error.hpp
"
31
#include "
NumCpp/Core/Shape.hpp
"
32
#include "
NumCpp/NdArray.hpp
"
33
34
#include <initializer_list>
35
#include <string>
36
37
namespace
nc
38
{
39
//============================================================================
40
// Method Description:
50
template
<
typename
dtype>
51
NdArray<dtype>
column_stack
(
const
std::initializer_list<
NdArray<dtype>
>& inArrayList)
52
{
53
// first loop through to calculate the final size of the array
54
Shape
finalShape;
55
for
(
auto
& ndarray : inArrayList)
56
{
57
if
(finalShape.
isnull
())
58
{
59
finalShape = ndarray.shape();
60
}
61
else
if
(ndarray.shape().rows != finalShape.
rows
)
62
{
63
THROW_INVALID_ARGUMENT_ERROR
(
"input arrays must have the same number of rows."
);
64
}
65
else
66
{
67
finalShape.
cols
+= ndarray.shape().cols;
68
}
69
}
70
71
// now that we know the final size, contruct the output array
72
NdArray<dtype>
returnArray(finalShape);
73
uint32
colStart = 0;
74
for
(
auto
& ndarray : inArrayList)
75
{
76
const
Shape
theShape = ndarray.shape();
77
for
(
uint32
row = 0; row < theShape.
rows
; ++row)
78
{
79
for
(
uint32
col = 0; col < theShape.
cols
; ++col)
80
{
81
returnArray(row, colStart + col) = ndarray(row, col);
82
}
83
}
84
colStart += theShape.
cols
;
85
}
86
87
return
returnArray;
88
}
89
}
// namespace nc
Error.hpp
nc::Shape::isnull
bool isnull() const noexcept
Definition:
Core/Shape.hpp:113
nc::NdArray< dtype >
nc::uint32
std::uint32_t uint32
Definition:
Types.hpp:40
nc::column_stack
NdArray< dtype > column_stack(const std::initializer_list< NdArray< dtype > > &inArrayList)
Definition:
column_stack.hpp:51
NdArray.hpp
nc::Shape
A Shape Class for NdArrays.
Definition:
Core/Shape.hpp:40
nc::Shape::cols
uint32 cols
Definition:
Core/Shape.hpp:45
Shape.hpp
nc
Definition:
Coordinate.hpp:44
nc::Shape::rows
uint32 rows
Definition:
Core/Shape.hpp:44
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition:
Error.hpp:36
include
NumCpp
Functions
column_stack.hpp
Generated by
1.8.17