久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在列表中查找列的總和得到“TypeError: cannot perf

Finding Sum of a Column in a List Getting quot;TypeError: cannot perform reduce with flexible typequot;(在列表中查找列的總和得到“TypeError: cannot perform reduce with flexible type)
本文介紹了在列表中查找列的總和得到“TypeError: cannot perform reduce with flexible type"的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

所以我是 python 新手,并且已經搜索過這個答案,但大多數回復都在我的腦海中.我有一個這樣的列表:

So I am new to python and have searched for this answer but most responses are over my head. I have a list like this:

right point point 1.76999998093
right fear fear 1.62700009346
right sit sit 1.46899986267
right chord chord 1.47900009155
right speed speeed 1.71300005913
right system system 1.69799995422
right hard hard 1.4470000267
right excite excite 2.93799996376
right govern govern 1.85800004005
right record record 1.62400007248

我正在嘗試將列表拆分為列并找到數字的均值/總和/標準差.所以基本上我只是想把最后一個變成一個數組形式,我可以使用 np.mean、np.sum 等.數據在一個名為正確"的文件中這是我目前所擁有的:

I am trying to split the list into columns and find the mean/sum/std dev of the numbers. So basically i am just trying to get the last into an array form I can use np.mean, np.sum, etc with. The data is in a file called 'right' Here is what I have so far:

right=open('right.txt').readlines()
for line in right: 
    l=line.split()
    righttime=l[3]
    print righttime

rightsum=np.sum(righttime)
rightmean=np.mean(righttime)

然后我得到這個錯誤:TypeError: cannot perform reduce with flexible type"我已經嘗試了很多方法并且不斷出錯.這是我嘗試過的另一種看起來很有希望的方法:

Then I get this error: "TypeError: cannot perform reduce with flexible type" I have tried it tons of ways and keep getting errors. This is another way I tried that seemed promising:

def TimeSum(data):
    for line in data: 
        l=line.split()
        righttime=l[3]
        print righttime
    return righttime

rightsum=np.sum(TimeSum(right))

但我有同樣的錯誤.有誰知道怎么做?

But I had the same error. Does anyone know how to do this?

推薦答案

生成一個列表并對元素求和:

Generate a list and sum the elements:

import numpy as np

right = open('right.txt').readlines()
mylist = []

for line in right:
    l = line.split()  
    mylist.append(float(l[3])) # add to list "mylist"   

rightsum = np.sum(mylist)
print rightsum

或者,也可以

mylist = [float(line.split()[3]) for line in right] # generate numbers list
print np.sum(mylist) # sum numbers

這篇關于在列表中查找列的總和得到“TypeError: cannot perform reduce with flexible type"的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 亚洲精品乱| 荷兰欧美一级毛片 | 亚洲欧美视频一区 | 久久久久久免费毛片精品 | 日韩欧美二区 | 亚洲视频一区在线观看 | 欧美精品一区二区三区在线播放 | 成av在线 | 久久免费视频1 | 精品国产乱码 | 日韩中文字幕一区二区 | 日本在线视频中文字幕 | 国精久久 | 日本精品视频一区二区三区四区 | 欧美激情亚洲激情 | 国产资源在线视频 | 99精品免费 | 色婷婷影院 | 国产免费观看视频 | 国产免费福利 | 国产精品九九九 | av毛片在线播放 | 日本一二区视频 | 中文字幕在线看第二 | av黄色片在线观看 | 午夜激情影院 | 国产十日韩十欧美 | 粉嫩国产精品一区二区在线观看 | 久久一区二区三区电影 | 一级黄色片一级黄色片 | 国产精品美女一区二区 | 琪琪午夜伦伦电影福利片 | xxxcom在线观看 | 午夜精品视频在线观看 | 免费一级做a爰片久久毛片潮喷 | 国产精品久久久久久久久久久久 | 免费精品 | 日日天天| 国产欧美一区二区三区另类精品 | 欧美www在线 | 国产免费一区 |