Skip to content

Instantly share code, notes, and snippets.

@uchida
Created October 13, 2011 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uchida/1285432 to your computer and use it in GitHub Desktop.
Save uchida/1285432 to your computer and use it in GitHub Desktop.
Tokyo.Scipy#2 ディスカッション事前アンケート5
# -*- 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