CNTK将标签索引转换为单热矢量表示

时间:2017-03-20 08:58:41

标签: python cntk

将包含标签的矢量(仅仅是常规矢量,而不是稀疏表示)转换为一个热表示的CNTK方法是什么?以下是5个类的示例:

输入

[2, 0, 1, 1]

期望的输出:

[[0,0,1,0,0],
[1,0,0,0,0],
[0,1,0,0,0],
[0,1,0,0,0]]

有没有办法不通过Python / numpy?

1 个答案:

答案 0 :(得分:1)

以下是<form name="myForm" ng-submit="myForm.$valid"> <input type="checkbox" ng-model="obj.first" ng-change="onChange()" /> First <br /> <input type="checkbox" ng-model="obj.second" ng-change="onChange()"/>Second <br /> <input type="checkbox" ng-model="obj.third" ng-change="onChange()"/> Third <br> <button type="submit" ng-disabled="!myForm.$valid" ng-click="click()">test</button> <br> </form> $scope.myForm = {}; $scope.myForm.$valid = false; $scope.click=function () { console.log('-------------2', $scope.myForm); }; $scope.onChange=function () { console.log('before:', $scope.myForm); var isValid = false; angular.forEach($scope.obj, function(value, key) { if(value == true){ isValid=true; } console.log(key + ': ' + value); }); if(!isValid){ $scope.myForm.$valid = false; $scope.myForm.$error.checkBoxes = { isChecked: false }; } console.log('after:', $scope.myForm); } 的处理方法(假设您有一批4个标签):

one_hot