NumCpp
2.3.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
choice.hpp
Go to the documentation of this file.
1
#pragma once
29
30
#include "
NumCpp/Core/Shape.hpp
"
31
#include "
NumCpp/Core/Types.hpp
"
32
#include "
NumCpp/NdArray.hpp
"
33
#include "
NumCpp/Random/randInt.hpp
"
34
35
namespace
nc
36
{
37
namespace
random
38
{
39
//============================================================================
40
// Method Description:
47
template
<
typename
dtype>
48
dtype
choice
(
const
NdArray<dtype>
& inArray)
49
{
50
uint32
randIdx = random::randInt<uint32>(
Shape
(1), 0, inArray.
size
()).item();
51
return
inArray[randIdx];
52
}
53
54
//============================================================================
55
// Method Description:
64
template
<
typename
dtype>
65
NdArray<dtype>
choice
(
const
NdArray<dtype>
& inArray,
uint32
inNum)
66
{
67
NdArray<dtype>
outArray(1, inNum);
68
for
(
uint32
i = 0; i < inNum; ++i)
69
{
70
uint32
randIdx = random::randInt<uint32>(
Shape
(1), 0, inArray.
size
()).item();
71
outArray[i] = inArray[randIdx];
72
}
73
74
return
outArray;
75
}
76
}
// namespace random
77
}
// namespace nc
randInt.hpp
nc::NdArray< dtype >
nc::uint32
std::uint32_t uint32
Definition:
Types.hpp:40
NdArray.hpp
nc::Shape
A Shape Class for NdArrays.
Definition:
Core/Shape.hpp:40
nc::NdArray::size
size_type size() const noexcept
Definition:
NdArrayCore.hpp:4325
nc::random::choice
dtype choice(const NdArray< dtype > &inArray)
Definition:
choice.hpp:48
Shape.hpp
nc
Definition:
Coordinate.hpp:44
Types.hpp
include
NumCpp
Random
choice.hpp
Generated by
1.8.17