Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calculations using np.arrays in python

Tags:

python

numpy

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.

like image 700
AB567 Avatar asked Jun 29 '26 14:06

AB567


1 Answers

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

dataFast -= np.median(newLists)
like image 86
Saullo G. P. Castro Avatar answered Jul 02 '26 05:07

Saullo G. P. Castro