Vielleicht ist es nur spät am Tag, und ich bin ein Gehirn Furz zu haben, aber ...Gegenseitige scheinen gebrochen ... 1/y == y (aber y gut definiert ist und nicht 1)
- wenn y> 0 und y 1 <
- y gut (nicht NAN oder undefiniert) definiert ist
sollte dann nicht 1/y> 1 sein?
Ich sehe 1/y == y. (Das Gegenseitige ist ein No-Op).
# rr is a Series of dtype=float64
rr = rr.replace(np.inf, np.nan)
rr = rr.replace(-np.inf, np.nan)
rr = rr.replace(0, 999.9)
print rr.sum()
y = rr[(rr>0) & (rr<1)].copy() # include only those values >0, <1
print "A"
print y.tail()
print "B"
print (1./y).tail()
for i in y:
assert i>=0 and i<=1
for i in y:
i = 1/i
assert i>=1
for i in (1./y): # Seems like this look should be the same as the former.
print i, "GONNA FAIL"
assert i>=1
2125514.43816 # rr.sum() is well defined
A # y.tail()
0
229994 0.893194
229996 0.997238
229999 0.725193
230000 0.980193
230002 0.819778
Name: rr, dtype: float64
B # 1/y.tail() ALL THE SAME??!
0
229994 0.893194
229996 0.997238
229999 0.725193
230000 0.980193
230002 0.819778
Name: rr, dtype: float64
0.566025929312 GONNA FAIL
Traceback (most recent call last):
File "<stdin>", line 22, in <module>
AssertionError
... so etwas über pandas 1/Serie sieht ein wenig funky.
Ergebnisse sind die gleichen mit y.rtruediv(1)
.
Update: Link zu der CSV-Datei:
import pandas as pd
import numpy as np
import io
import requests
url="https://www.dropbox.com/s/2t03ia7vp1vfx0z/rr.csv?dl=1#"
s=requests.get(url).content
rr=pd.read_csv(io.StringIO(s.decode('utf-8')))
rr = rr[rr.columns[-1]].rename('rr')
print pd.__version__ # 0.19.2
print np.__version__ # 1.13.0
Hier ist ein Link auf die full code as a jupyter notebook.
Aktualisierung: Mehr logs and code in this folder.
Welche Version von Pandas (und Python) verwendest du? Ich habe 'rr = pd.read_csv (" https://www.dropbox.com/s/2t03ia7vp1vfx0z/rr.csv?dl=1# ", Namen = ['index', 'rr']) .rr' und lief alles von der 'replace' Linie ab, und es funktionierte gut. –
Sind Sie sicher, dass Sie '1./y.tail()' nicht anstelle von '(1./y) .tail()' 'gedruckt haben? – Kartik
@Kartik Das ist nicht wichtig wäre, weil 'y' nur Werte in (0,1) enthält, die durch Konstruktion, so dass alle Einträge von' 1/y' sind größer als 1. –