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

TypeError:迭代 0-d 數(shù)組 Python

TypeError: iteration over a 0-d array Python(TypeError:迭代 0-d 數(shù)組 Python)
本文介紹了TypeError:迭代 0-d 數(shù)組 Python的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在嘗試編寫一個非常基本的最近鄰計算.我基本上想看看 t 的樣子,但我得到了這種類型的錯誤.當(dāng)我要求功能返回時,它說".當(dāng)我要求它轉(zhuǎn)入列表時,它拋出TypeError:迭代 0-d 數(shù)組 Python"

I am trying to write a very basic nearest neighbor calculation. I basically want to see what t looks like but I got this type error. When I asked the funciton to return just t it said "". When I asked it to turn to list it threw "TypeError: iteration over a 0-d array Python "

請問我該如何解決這個問題?

How do I fix this please?

...

t = np.array(map(lambda v:
             map(lambda w: distance(v, w, L), x_train.values),
             x_test.values)) 

...

完整的跟蹤:

推薦答案

問題是np.array不帶迭代器,需要先轉(zhuǎn)換成list,如下:

The problem is np.array does not take an iterator, you need convert to list first, as below:

t = np.array(list(map(lambda v: map(lambda w: distance(v, w, L),
                      x_train.values), x_test.values)))

根據(jù) numpy.array 文檔,必填參數(shù)必須是:

As per numpy.array documentation, the required parameter must be:

一個數(shù)組,任何暴露數(shù)組接口的對象,一個對象array 方法返回一個數(shù)組,或任何(嵌套)序列.

An array, any object exposing the array interface, an object whose array method returns an array, or any (nested) sequence.

或者,使用 numpy.fromiter 并記得提供 dtype,例如dtype=float.

這篇關(guān)于TypeError:迭代 0-d 數(shù)組 Python的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Troubles while parsing with python very large xml file(使用 python 解析非常大的 xml 文件時出現(xiàn)問題)
Find all nodes by attribute in XML using Python 2(使用 Python 2 在 XML 中按屬性查找所有節(jié)點)
Python - How to parse xml response and store a elements value in a variable?(Python - 如何解析 xml 響應(yīng)并將元素值存儲在變量中?)
How to get XML tag value in Python(如何在 Python 中獲取 XML 標(biāo)記值)
How to correctly parse utf-8 xml with ElementTree?(如何使用 ElementTree 正確解析 utf-8 xml?)
Parse XML from URL into python object(將 XML 從 URL 解析為 python 對象)
主站蜘蛛池模板: 一区二区三区在线播放 | 欧美视频免费 | 91伊人| 国产一级在线观看 | 91大神在线资源观看无广告 | 高清一区二区三区 | 日韩在线观看视频一区 | www国产亚洲精品 | 99久久久久久久 | 日韩视频二区 | 亚洲免费视频一区二区 | 免费观看黄a一级视频 | 91视视频在线观看入口直接观看 | 久久久久国产精品一区二区 | 中文字幕日韩在线 | 日本在线精品视频 | 国产福利在线免费观看 | 国产ts一区 | 综合自拍 | 99久久婷婷国产综合精品电影 | 久久国产成人 | av一级毛片 | 国产精品亚洲第一区在线暖暖韩国 | 亚洲伊人久久综合 | 日韩av看片 | 日韩视频二区 | 黑人巨大精品欧美一区二区免费 | 久久精品无码一区二区三区 | 五月天婷婷激情 | 国产精品久久久久久久久久了 | 日本一区二区在线视频 | 青青久视频 | 国产激情视频在线观看 | 午夜精品一区二区三区在线观看 | 国产午夜在线 | 亚洲最新在线 | 久久久久一区 | 久久极品 | 久久精品国产99国产精品 | 久久99精品久久久久久秒播九色 | 久久一区精品 |