Skip to content

Instantly share code, notes, and snippets.

@uchida
Created October 13, 2011 20:29
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/1285419 to your computer and use it in GitHub Desktop.
Save uchida/1285419 to your computer and use it in GitHub Desktop.
Tokyo.Scipy#2 ディスカッション事前アンケート4
# -*- 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