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.
Join the #python-forum IRC channel on for off-topic chat!

Please prefer not to PM members. The point of the forum is so that anyone can benefit. We don't want to help you over PMs/emails/Skype chats that others can't benefit from :)
User avatar
Posts: 2118
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: ChrisOfBristol and 8 guests