久久久久久久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 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 午夜影院在线播放 | 一区2区 | 久久久精品网 | 国产欧美精品区一区二区三区 | 国产成人午夜高潮毛片 | 99久久精品国产一区二区三区 | 亚洲激情综合 | 在线视频中文字幕 | 亚洲国产aⅴ精品一区二区 免费观看av | 国产精品一区二 | 91九色网站| 亚洲天堂av一区 | 久久久久久国产精品 | 99re在线视频| 网站黄色在线免费观看 | 天堂久久一区 | 人人天天操 | 欧美一级视频在线观看 | 欧美日韩在线一区二区 | 日韩欧美中文 | 国产精品亚洲成在人线 | 欧美另类视频在线 | 亚洲二区视频 | 日韩欧美1区2区 | 亚洲精品99999| 亚洲一区二区三区四区五区午夜 | 欧美一区2区三区4区公司二百 | 日韩蜜桃视频 | 日韩中文视频 | 欧美性高潮 | 国产一区二区三区 | 毛片网站在线观看 | 久久久999免费视频 999久久久久久久久6666 | 亚洲精品久久嫩草网站秘色 | 欧美精品在线一区 | 国产一区二区三区在线看 | 久久婷婷国产香蕉 | 日韩视频一区在线观看 | 在线激情视频 | 欧美日韩国产精品激情在线播放 | 天天搞夜夜操 |