我的数据格式如下:
1495573445.162, 0, 0.021973, 0.012283, -0.995468, 1
1495573445.172, 0, 0.021072, 0.013779, -0.994308, 1
1495573445.182, 0, 0.020157, 0.015717, -0.995575, 1
1495573445.192, 0, 0.017883, 0.012756, -0.993927, 1
1495573445.202, 0, 0.021194, 0.012161, -0.994705, 1
没有标题。大约有1000个相似的行。
我想将第三,第四和第五列标准化为np数组。
我有以下代码。
import numpy as np
Acc1_x = np.genfromtxt('Accelerometer1.csv', delimiter=',')
Acc1_y = np.genfromtxt('Accelerometer1.csv', delimiter=',')
Acc1_z = np.genfromtxt('Accelerometer1.csv', delimiter=',')
Acc2_x = np.genfromtxt('Accelerometer2.csv', delimiter=',')
Acc2_y = np.genfromtxt('Accelerometer2.csv', delimiter=',')
Acc2_z = np.genfromtxt('Accelerometer2.csv', delimiter=',')
Acc3_x = np.genfromtxt('Accelerometer3.csv', delimiter=',')
Acc3_y = np.genfromtxt('Accelerometer3.csv', delimiter=',')
Acc3_z = np.genfromtxt('Accelerometer3.csv', delimiter=',')
Acc1_x_normed = (Acc1_x - Acc1_x.min()) / Acc1_x.ptp()
Acc1_y_normed = (Acc1_y - Acc1_y.min()) / Acc1_y.ptp()
Acc1_z_normed = (Acc1_z - Acc1_y.min()) / Acc1_y.ptp()
Acc2_x_normed = (Acc2_x - Acc2_x.min()) / Acc2_x.ptp()
Acc2_y_normed = (Acc2_y - Acc2_y.min()) / Acc2_y.ptp()
Acc2_z_normed = (Acc2_z - Acc2_z.min()) / Acc2_z.ptp()
Acc3_x_normed = (Acc3_x - Acc3_x.min()) / Acc3_x.ptp()
Acc3_y_normed = (Acc3_y - Acc3_y.min()) / Acc3_y.ptp()
Acc3_z_normed = (Acc3_z - Acc3_z.min()) / Acc3_z.ptp()
print Acc1_x_normed
print Acc1_y_normed
print Acc1_z_normed
print Acc2_x_normed
print Acc2_y_normed
print Acc2_z_normed
print Acc3_x_normed
print Acc3_y_normed
print Acc3_z_normed
然而,打印出来:
[ 1.00000000e+00 6.65681116e-10 6.79158889e-10 6.76190128e-10
0.00000000e+00 1.33432096e-09]
[ 1.00000000e+00 6.64579197e-10 6.76536483e-10 6.73108367e-10
0.00000000e+00 1.33321904e-09]
[ 1.00000000e+00 6.64579197e-10 6.78750350e-10 6.72710526e-10
-5.20201801e-13 1.33321904e-09]
[ 1.00000000e+00 6.64916187e-10 6.79567423e-10 6.72057929e-10
0.00000000e+00 1.33355603e-09]
[ 1.00000000e+00 6.65568779e-10 6.81056484e-10 6.73282209e-10
0.00000000e+00 1.33420862e-09]
[ 1.00000000e+00 6.64252896e-10 6.78771073e-10 6.71313064e-10
0.00000000e+00 1.33289274e-09]
[ 1.00000000e+00 6.61436566e-10 6.71241501e-10 6.69088480e-10
0.00000000e+00 1.33007639e-09]
[ 1.00000000e+00 6.70966021e-10 6.84606942e-10 6.79750611e-10
0.00000000e+00 1.33960584e-09]
[ 1.00000000e+00 6.70894477e-10 6.84147587e-10 6.82066111e-10
0.00000000e+00 1.33953430e-09]
我需要它来打印csv文件中每个列中的整个1000左右的值,但它只在每个数组中打印出6个。
答案 0 :(得分:1)
你非常 关闭只需添加逻辑 axis = 0 所以
Acc1_x_normed = (Acc1_x - Acc1_x.min()) / Acc1_x.ptp()
变为
Acc1_x_normed = (Acc1_x - Acc1_x.min(axis=0)) / Acc1_x.ptp(axis=0)