为什么python numpy std()会产生不需要的空格?

2024-09-30 04:30:11 发布

您现在位置:Python中文网/ 问答频道 /正文

'car3.csv' file download link

import csv
num = open('car3.csv')
nums = csv.reader(num)
nums_list = []
for i in nums:
    nums_list.append(i)

import numpy as np
nums_arr = np.array(nums_list, dtype = np.float32)
print(nums_arr)
print(np.std(nums_arr, axis=0))

结果就是这样。你知道吗


[[ 1.  1.  2.]
 [ 1.  1.  2.]
 [ 1.  1.  2.]
 ..., 
 [ 0.  0.  5.]
 [ 0.  0.  5.]
 [ 0.  0.  5.]]
[ 0.5         0.5         1.11803401]

有很多我没想到的地方。 我怎么处理这些?你知道吗


Tags: csvimportfordownloadnplinkopennum
1条回答
网友
1楼 · 发布于 2024-09-30 04:30:11

这不是间距问题。你所需要做的就是保存标准差的输出。然后,您可以按如下方式访问每个值:

 std_arr = np.std(nums_arr, axis=0) # array which holds std of each column

 # now, you can access them by indexing: 
 print(std_arr[0]) # output here is 0.5
 print(std_arr[1]) # output here is 0.5
 print(std_arr[2]) # output here is 1.118034

相关问题 更多 >

    热门问题