FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
TensorFlow.NET/src/TensorFlowNET.Keras/Utils/np_utils.cs at master · MSavameri/TensorFlow.NET · GitHub
MSavameri
TensorFlow.NET
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
TensorFlow.NET
/
src
/
TensorFlowNET.Keras
/
Utils
/
np_utils.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
31 lines (29 loc) · 980 Bytes
Breadcrumbs
TensorFlow.NET
/
src
/
TensorFlowNET.Keras
/
Utils
/
np_utils.cs
Copy path
File metadata and controls
31 lines (29 loc) · 980 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using
Tensorflow
.
NumPy
;
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
Text
;
namespace
Tensorflow
.
Keras
.
Utils
{
public
class
np_utils
{
/// <summary>
/// Converts a class vector (integers) to binary class matrix.
/// </summary>
/// <param name="y"></param>
/// <param name="num_classes"></param>
/// <param name="dtype"></param>
/// <returns></returns>
public
static
NDArray
to_categorical
(
NDArray
y
,
int
num_classes
=
-
1
,
TF_DataType
dtype
=
TF_DataType
.
TF_FLOAT
)
{
var
y1
=
y
.
astype
(
np
.
int32
)
.
ToArray
<
int
>
(
)
;
// var input_shape = y.shape[..^1];
var
categorical
=
np
.
zeros
(
(
(
int
)
y
.
size
,
num_classes
)
,
dtype
:
dtype
)
;
// categorical[np.arange(y.size), y] = 1;
for
(
var
i
=
0
;
i
<
(
int
)
y
.
size
;
i
++
)
{
categorical
[
i
,
y1
[
i
]
]
=
1.0f
;
}
return
categorical
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL