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.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.0);
118 returnArray(0, row) =
sum / weightSum;
132 const Shape transShape = transposedArray.
shape();
133 double weightSum = inWeights.template astype<double>().
sum().item();
135 for (
uint32 row = 0; row < transShape.
rows; ++row)
139 transposedArray.
cend(row),
141 weightedArray.
begin(),
142 std::multiplies<double>());
144 double sum = std::accumulate(weightedArray.
begin(), weightedArray.
end(), 0.0);
145 returnArray(0, row) =
sum / weightSum;
169 template<
typename dtype>
170 NdArray<std::complex<double>>
175 const auto multiplies = [](
const std::complex<dtype>& lhs, dtype rhs) -> std::complex<double>
176 {
return complex_cast<double>(lhs) *
static_cast<double>(rhs); };
182 if (inWeights.
shape() != inArray.shape())
191 weightedArray.
begin(),
194 std::complex<double>
sum =
195 std::accumulate(weightedArray.
begin(), weightedArray.
end(), std::complex<double>(0.0));
202 const Shape arrayShape = inArray.shape();
203 if (inWeights.
size() != arrayShape.
cols)
208 double weightSum = inWeights.template astype<double>().
sum().item();
210 for (
uint32 row = 0; row < arrayShape.
rows; ++row)
216 weightedArray.
begin(),
219 const std::complex<double>
sum =
220 std::accumulate(weightedArray.
begin(), weightedArray.
end(), std::complex<double>(0.0));
221 returnArray(0, row) =
sum / weightSum;
228 if (inWeights.
size() != inArray.shape().rows)
235 const Shape transShape = transposedArray.
shape();
236 double weightSum = inWeights.template astype<double>().
sum().item();
238 for (
uint32 row = 0; row < transShape.
rows; ++row)
242 transposedArray.
cend(row),
244 weightedArray.
begin(),
247 const std::complex<double>
sum =
248 std::accumulate(weightedArray.
begin(), weightedArray.
end(), std::complex<double>(0.0));
249 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:4289
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1221
iterator end() noexcept
Definition: NdArrayCore.hpp:1479
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4276
NdArray< dtype > sum(Axis inAxis=Axis::NONE) const
Definition: NdArrayCore.hpp:4382
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4650
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