NumCpp
NumCpp copied to clipboard
outer function currently doesn't support input arrays of different sizes
Describe the bug outer function currently doesn't support input arrays of different sizes
To Reproduce
nc::NdArray<double> x = {1., 2.}; nc::NdArray<double> y = {1., 2., 3.}; auto output = nc::outer (x, z);
Expected behavior output should be something like { {1, 2, 3}, {2, 4, 6} }
Code suggestions In addition to below, it would be good for the function to flatten the input arrays.
`
template
const auto size1 = inArray1.size();
const auto size2 = inArray2.size();
auto returnArray = NdArray<dtype>(size1, size2);
for (uint32 row = 0; row < size1; ++row)
{
const auto array1Value = inArray1[row];
std::transform(inArray2.begin(), inArray2.end(), returnArray.begin(row),
[array1Value](dtype value) -> dtype
{
return array1Value * value;
});
}
return returnArray;
} `
Fixed in Version 2.16.0.