Created
October 13, 2011 20:29
-
-
Save uchida/1285419 to your computer and use it in GitHub Desktop.
Tokyo.Scipy#2 ディスカッション事前アンケート4
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 | |
# | |
# 4. nanを含む4x2行列 | |
# m = numpy.array([[1,nan,-1,0],[0,0,nan,1]]) | |
# が与えられたとき、 | |
# nanを含む行を削除して2x2行列にする方法が直ぐに思い浮かびますか? | |
from numpy import array | |
from numpy import nan, isnan | |
from numpy import logical_or, logical_not | |
from numpy import tile | |
m = array([[1, nan, -1, 0],[0, 0, nan, 1]]) | |
nans = logical_or(isnan(m[0]), isnan(m[1])) | |
mask = tile(logical_not(nans), (2,1)) | |
res = m[mask].reshape(2,2) | |
print res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment