Skip to content

Instantly share code, notes, and snippets.

@uchida
Created October 13, 2011 20:26
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/1285408 to your computer and use it in GitHub Desktop.
Save uchida/1285408 to your computer and use it in GitHub Desktop.
Tokyo.Scipy#2 ディスカッション事前アンケート3
# -*- coding:utf8 -*-
# Tokyo.Scipy#2 ディスカッション事前アンケート
# http://www.surveymonkey.com/s/XJ2KNBW
#
# 3. nanやInfを含む値の列
# x = numpy.array([[1,0,nan,1,Inf,1,....]])
# が与えられたとき、
# NaNやInf以外のxの要素の合計を計算する方法が直ぐに思い浮かびますか?
from numpy import array
from numpy import nan, Inf, isfinite
x = array([[1, 0, nan, 1, Inf, 1]])
res = sum(x[isfinite(x)])
print res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment