gpt4 book ai didi

python - 如何将 CSV 列转换为标准化 np 数组?

转载 作者:太空宇宙 更新时间:2023-11-03 15:11:03 25 4
gpt4 key购买 nike

我有以下格式的数据:

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 个值。

最佳答案

非常接近只需要添加逻辑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)

关于python - 如何将 CSV 列转换为标准化 np 数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44208208/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com