55 template<
typename dtype>
58 return mean(inArray, inAxis);
72 template<
typename dtype>
90 weightedArray.
begin(),
91 std::multiplies<double>());
93 double sum = std::accumulate(weightedArray.
begin(), weightedArray.
end(), 0.);
101 if (inWeights.
size() != arrayShape.
cols)
106 double weightSum = inWeights.template astype<double>().
sum().item();
108 for (
uint32 row = 0; row < arrayShape.
rows; ++row)
114 weightedArray.
begin(),
115 std::multiplies<double>());
117 double sum = std::accumulate(weightedArray.
begin(), weightedArray.
end(), 0.);
118 returnArray(0, row) =
sum / weightSum;
146 template<
typename dtype>
147 NdArray<std::complex<double>>
152 const auto multiplies = [](
const std::complex<dtype>& lhs, dtype rhs) -> std::complex<double>
153 {
return complex_cast<double>(lhs) *
static_cast<double>(rhs); };
159 if (inWeights.
shape() != inArray.shape())
168 weightedArray.
begin(),
171 std::complex<double>
sum =
172 std::accumulate(weightedArray.
begin(), weightedArray.
end(), std::complex<double>(0.));
179 const Shape arrayShape = inArray.shape();
180 if (inWeights.
size() != arrayShape.
cols)
185 double weightSum = inWeights.template astype<double>().
sum().item();
187 for (
uint32 row = 0; row < arrayShape.
rows; ++row)
193 weightedArray.
begin(),
196 const std::complex<double>
sum =
197 std::accumulate(weightedArray.
begin(), weightedArray.
end(), std::complex<double>(0.));
198 returnArray(0, row) =
sum / weightSum;
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
#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:4105
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1221
iterator end() noexcept
Definition: NdArrayCore.hpp:1479
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4092
NdArray< dtype > sum(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:4198
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4457
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1529
iterator begin() noexcept
Definition: NdArrayCore.hpp:1171
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
uint32 rows
Definition: Core/Shape.hpp:44
uint32 cols
Definition: Core/Shape.hpp:45
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:784
Definition: Coordinate.hpp:45
Axis
Enum To describe an axis.
Definition: Types.hpp:47
auto average(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: average.hpp:56
NdArray< dtype > sum(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: sum.hpp:46
NdArray< double > mean(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: mean.hpp:52
std::uint32_t uint32
Definition: Types.hpp:40