I have a dataframe which contains 3 columns and 100 rows, I converted this dataframe to numpy array, because i want it as a matrix, this array has the dimensions of (10,10,3) it means it is a (10*10) matrix,and each element inside the matrix has 3 values, I want to apply an if function in each element,and replace the element with the result of this function. this is how the dataframe looked like:
fromlinkno vianodeno tolinkno
0 15 1 16
1 16 1 15
2 25 2 26
3 16 3 17
.. .. .. ..
95 44 43 28
96 28 35 29
[100 rows * 3 columns]
import pandas as pd
import numpy as np
df2=df.iloc[:100]
arr=df2.to_numpy()
arr.reshape(10,10,3)
The array(matrix) looks like:
[[[15 1 16]
[16 1 15]
[25 2 26]
[16 3 17]
[17 3 16]
[17 4 18]
[18 4 17]
[18 5 19]
[19 5 18]
[19 6 20]]
[[19 6 34]
............
............]
............
...........
[44 43 28]
[28 35 29]]
I want to apply this function for example:
if (fromlinkno> tolinkno):
if(tolinkno > vianodeno):
return A
elif(tolinkno vianodeno):
return C
elif(tolinkno < vianodeno):
return D
how can i do that?