Compare array with number

This is the place for queries that don't fit in any of the other categories.

Compare array with number

Postby Marleb » Mon Aug 12, 2013 6:18 am

ich want to replace values that differ more than 50% from my mean value by the vell before. The ocurring error is: "The truth value of an array with more than one element is ambigous. Use a.any() or a.all()."
Any ideas?

import csv
import pandas as pd
import numpy as np
from scipy import *
from numpy import *
import matplotlib.pyplot as plt

dF = pd.read_csv("Example.csv", sep=';')
xresult = []
#xresult = [abs(dF.x)]

xresult = dF.x.fillna(method = 'ffill') #bfill=backwardfill, ffill is filling the list with value before if na(=NaN)

xresult = [abs(xresult)]

print xresult

print k
print (np.std(xresult))

m = k*1.50
n = k*0,5t
print m
print n

for i in range(len(dF.x)):
if dF.x[i+1] > m:#if you compare a numpy array with a number you get another array
dF.x[i+1] = dF.x[i]
if dF.x[i+1] < n:
dF.x[i+1] = dF.x[i]
Posts: 3
Joined: Mon Aug 05, 2013 10:08 am

Re: Compare array with number

Postby micseydel » Mon Aug 12, 2013 6:32 am

You've been warned twice before about code tags. Consider this a formal warning.
Due to the reasons discussed here we will be moving to on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Compare array with number

Postby tnknepp » Mon Aug 12, 2013 3:00 pm

Agreeing with micseydel: code tags man! Im Forum haben wir Regeln. Wenn wir unsere Code schreiben, und Hilfe möchten haben, mussen wir die richtige format nutzen.

Anyway, change this line:
Code: Select all
n = k*0,5t # Wrong
n = k*0.5t # Correct
Python: 2.7 via Anaconda
Numpy: 1.7
Pandas: 0.11
OS: Windows 7
IDE: Spyder/IPython
User avatar
Posts: 153
Joined: Mon Mar 11, 2013 7:41 pm

Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 13 guests