3

I am really struggling to understand how to perform calculations with numpy arrays.

myList = open('key_resp.csv')
newList = np.array(myList)

newList2=sorted(newList)

newLists = open("dataSorted.csv",'w')
writer = csv.writer(newLists)
writer.writerow(newList2)

medNumber=np.median(newLists)

fast = newList2[:len(newList2)//2]
slow = newList2[len(newList2)//2:]


dataFast = open("dataFast.csv",'w')
writer = csv.writer(dataFast)
writer.writerow(fast)

Now for every value in dataFast I want to subtract medNumber.

dataFast.csv looks like [0.1] [0.2] [0.3] in csv file.

1
  • 1
    Note that numpy array have a sort method. Using sorted will convert them to a python list and you will loose any advantage of speed/memory you had with the arrays. Commented Jun 8, 2013 at 16:32

1 Answer 1

2

You can subtract in place (without copying the array) doing:

dataFast -= np.median(newLists)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.