首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >木星笔记本:Pyhon3

木星笔记本:Pyhon3
EN

Stack Overflow用户
提问于 2021-02-26 12:53:27
回答 1查看 69关注 0票数 0

我通过上传整个代码编辑了我的问题,所以如果您能够检查这个@Nathon_Marotte先生。我试图运行这段代码,它给了我一个错误:

代码语言:javascript
复制
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
observations = 1000
xs = np.random.uniform(low=-10, high=10, size=(observations,1))
zs = np.random.uniform(-10,10,(observations,1))

inputs = np.column_stack((xs,zs))
print(inputs.shape)
noise= np.random.uniform(-1, 1, (observations, 1))
targets = 2*xs - 3*zs + 5 + noise
print(targets.shape)

#observations=1000
targets = targets.reshape(observations,)
fig=plt.figure()
ax = fig.add_subplot(111,projection='3d')

ax.plot(xs, zs, targets)

ax.set_xlabel('xs')
ax.set_ylabel('zs')
ax.set_zlabel('Targets')
ax.view_init(azim=250)
plt.show()
targets=targets.reshape(observations,)

错误:

代码语言:javascript
复制
ValueError                                Traceback (most recent call last)
<ipython-input-44-28d2a78b4ad5> in <module>
      3 ax = fig.add_subplot(111,projection='3d')
      4 
----> 5 ax.plot(xs, zs, targets)
      6 
      7 ax.set_xlabel('xs')

F:\Softwares\Anaconda\Installed\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py in plot(self, xs, ys, zdir, *args, **kwargs)
   1467 
   1468         # Match length
-> 1469         zs = np.broadcast_to(zs, np.shape(xs))
   1470 
   1471         lines = super().plot(xs, ys, *args, **kwargs)

<__array_function__ internals> in broadcast_to(*args, **kwargs)

F:\Softwares\Anaconda\Installed\lib\site-packages\numpy\lib\stride_tricks.py in broadcast_to(array, shape, subok)
    178            [1, 2, 3]])
    179     """
--> 180     return _broadcast_to(array, shape, subok=subok, readonly=True)
    181 
    182 

F:\Softwares\Anaconda\Installed\lib\site-packages\numpy\lib\stride_tricks.py in _broadcast_to(array, shape, subok, readonly)
    121                          'negative')
    122     extras = []
--> 123     it = np.nditer(
    124         (array,), flags=['multi_index', 'refs_ok', 'zerosize_ok'] + extras,
    125         op_flags=['readonly'], itershape=shape, order='C')

ValueError: operands could not be broadcast together with remapped shapes [original->remapped]: (1000,) and requested shape (1000,1)

因为我是个新手,没有足够的知识来解决这个问题。你能帮我解决这个问题吗?那太好了。

提前感谢你。

EN

回答 1

Stack Overflow用户

发布于 2021-02-26 16:37:26

我的问题结束了,当我使用Google资源时,它起了作用。谢谢大家,特别是@NathanMarotte

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66386172

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档