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