Created
October 13, 2011 20:31
-
-
Save uchida/1285432 to your computer and use it in GitHub Desktop.
Tokyo.Scipy#2 ディスカッション事前アンケート5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf8 -*- | |
# Tokyo.Scipy#2 ディスカッション事前アンケート | |
# http://www.surveymonkey.com/s/XJ2KNBW | |
# | |
# 5. numpy.array([[1,3,2]]) を、1-of-K表記法変換して | |
# numpy.array([[1,0,0],[0,0,1],[0,1,0]]) | |
# にする処理方法が直ぐに思い浮かびますか? | |
from numpy import array, zeros | |
code = array([[1, 3, 2]]) | |
n = code.size | |
res = zeros((n, n)) | |
indices = [i*n+c-1 for i, c in enumerate(code[0])] | |
res.put(indices, 1) | |
print res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment