久久久久久久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"的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習吧!

問題描述

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

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

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

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"我已經(jīng)嘗試了很多方法并且不斷出錯.這是我嘗試過的另一種看起來很有希望的方法:

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

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

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

相關(guān)文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區(qū)域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應(yīng)用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據(jù)文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 亚洲最大黄色 | 国产三级精品视频 | 99色在线 | 91精品国产综合久久久蜜臀 | 91色视频| 天堂av影院 | 三级av在线| 久久精品毛片 | 国产日本在线 | 九九九视频 | 成人黄色免费网站 | 免费三级黄色片 | 精品一区二区三 | 视频在线一区二区 | 色婷婷在线视频 | 在线综合网 | 中文字幕播放 | 欧美激情亚洲 | 亚洲一二区 | 97色婷婷| 日韩精品国产一区 | 成人午夜视频在线观看 | 涩涩久久| 久久免费视频网站 | 九色在线视频 | 国产综合在线视频 | 国产一级生活片 | 亚洲综合视频在线观看 | 免费黄色一级视频 | 中文字幕欧美在线 | 亚洲人天堂| 日韩在线免费视频 | 欧美一区二区三区的 | 91视频在线 | 国产一区二区自拍 | 在线看的av| 亚洲高清在线视频 | 亚洲狠狠干 | 色在线视频 | 特一级黄色片 | 国产网站在线 |