import pandas as pd
import numpy as np
df = pd.DataFrame(
{'A1': np.array([1. , 0.8787]),
'A2': np.array([ 0.73376, -0.14261]),
'A3': np.array([0.9179 , 0.59273]),
'A4': np.array([ 0.869011, -0.32241])})
df = df.sub(df['A1'], axis=0)
print(df)
A1 A2 A3 A4
0 0.0 -0.26624 -0.08210 -0.130989
1 0.0 -1.02131 -0.28597 -1.201110
Update: and without pandas -
import numpy as np
d = {'A1': np.array([1. , 0.8787]),
'A2': np.array([ 0.73376, -0.14261]),
'A3': np.array([0.9179 , 0.59273]),
'A4': np.array([ 0.869011, -0.32241])}
print({k: v-d['A1'] for k,v in d.items()})
# {'A1': array([0., 0.]), 'A2': array([-0.26624, -1.02131]), 'A3': array([-0.0821 , -0.28597]), 'A4': array([-0.130989, -1.20111 ])}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…