python集合变成数组_Python(NumPy):集合只能映射rank 1数组

在尝试使用matplotlib的pcolor函数时遇到了'Collections can only map rank 1 arrays'错误。该错误源于尝试将一个rank 2的矩阵应用于不支持此类数组的函数。这个问题涉及到Python集合转换为数组以及NumPy中的一维数组处理。
摘要由CSDN通过智能技术生成

我遇到以下错误,我不知道为什么...

>>> x = np.matrix([[1,2,3,4]])

>>> x

matrix([[1, 2, 3, 4]])

>>> pcolor(x)

>>> show()

Traceback (most recent call last):

File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.py", line 54, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/figure.py", line 1006, in draw

func(*args)

File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.py", line 54, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axes.py", line 2086, in draw

a.draw(renderer)

File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.py", line 54, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/collections.py", line 755, in draw

return Collection.draw(self, renderer)

File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.py", line 54, in draw_wrapper

draw(artist, renderer, *args, **kwargs)

File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/collections.py", line 244, in draw

self.update_scalarmappable()

File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/collections.py", line 609, in update_scalarmappable

raise ValueError('Collections can only map rank 1 arrays')

ValueError: Collections can only map rank 1 arrays

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值