gpt4 book ai didi

python - 运行 Holoview 和弦图示例时出错

转载 作者:太空宇宙 更新时间:2023-11-03 19:45:45 28 4
gpt4 key购买 nike

我目前正在学习 HoloViews,想从主页重现和弦示例:

http://holoviews.org/gallery/demos/bokeh/route_chord.html

我将每行的行复制到我的 jupyter-nb 中,并且此行始终出现错误:

chord = hv.Chord((route_counts, nodes), ['SourceID', 'DestinationID'], ['Stops'])

错误信息是:

TypeError                                 Traceback (most recent call last)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\core\function_base.py in linspace(start, stop, num, endpoint, retstep, dtype, axis)
116 try:
--> 117 num = operator.index(num)
118 except TypeError:

TypeError: 'numpy.float64' object cannot be interpreted as an integer

During handling of the above exception, another exception occurred:

TypeError Traceback (most recent call last)
<ipython-input-13-b727deae3660> in <module>
----> 1 chord = hv.Chord((route_counts, nodes), ['SourceID', 'DestinationID'], ['Stops'])
2

~\AppData\Local\Continuum\anaconda3\lib\site-packages\holoviews\element\graphs.py in __init__(self, data, kdims, vdims, compute, **params)
768 if compute:
769 self._nodes = nodes
--> 770 chord = layout_chords(self)
771 self._nodes = chord.nodes
772 self._edgepaths = chord.edgepaths

~\AppData\Local\Continuum\anaconda3\lib\site-packages\param\parameterized.py in __new__(class_, *args, **params)
2810 inst = class_.instance()
2811 inst.param._set_name(class_.__name__)
-> 2812 return inst.__call__(*args,**params)
2813
2814 def __call__(self,*args,**kw):

~\AppData\Local\Continuum\anaconda3\lib\site-packages\holoviews\core\operation.py in __call__(self, element, **kwargs)
162 elif 'streams' not in kwargs:
163 kwargs['streams'] = self.p.streams
--> 164 return element.apply(self, **kwargs)
165
166

~\AppData\Local\Continuum\anaconda3\lib\site-packages\holoviews\core\accessors.py in __call__(self, function, streams, link_inputs, dynamic, **kwargs)
108 if hasattr(function, 'dynamic'):
109 inner_kwargs['dynamic'] = False
--> 110 return function(self._obj, **inner_kwargs)
111 elif self._obj._deep_indexable:
112 mapped = []

~\AppData\Local\Continuum\anaconda3\lib\site-packages\holoviews\core\operation.py in __call__(self, element, **kwargs)
159 for k, el in element.items()])
160 elif isinstance(element, ViewableElement):
--> 161 return self._apply(element)
162 elif 'streams' not in kwargs:
163 kwargs['streams'] = self.p.streams

~\AppData\Local\Continuum\anaconda3\lib\site-packages\holoviews\core\operation.py in _apply(self, element, key)
119 for hook in self._preprocess_hooks:
120 kwargs.update(hook(self, element))
--> 121 ret = self._process(element, key)
122 for hook in self._postprocess_hooks:
123 ret = hook(self, ret, **kwargs)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\holoviews\element\graphs.py in _process(self, element, key)
677 n_conn = weights_of_areas[i]
678 p0, p1 = points[i], points[i+1]
--> 679 angles = np.linspace(p0, p1, n_conn)
680 coords = list(zip(np.cos(angles), np.sin(angles)))
681 all_areas.append(coords)

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

~\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\core\function_base.py in linspace(start, stop, num, endpoint, retstep, dtype, axis)
119 raise TypeError(
120 "object of type {} cannot be safely interpreted as an integer."
--> 121 .format(type(num)))
122
123 if num < 0:

TypeError: object of type <class 'numpy.float64'> cannot be safely interpreted as an integer.

非常感谢任何帮助。

最佳

根据要求:

print((type(route_counts), type(nodes)))
print((route_counts.dtypes))

(<class 'pandas.core.frame.DataFrame'>, <class 'holoviews.core.data.Dataset'>)
SourceID int64
DestinationID int64
Stops int64
dtype: object

软件包和版本:

holoviews                 1.12.7                     py_0    pyviz
pandas 1.0.0 py37h47e9c7a_0
numpy 1.18.1 py37h93ca92e_0
bokeh 1.4.0 py37_0

尝试下载的笔记本并收到相同的错误消息。

最佳答案

这是一个错误。处理 numpy 1.18.1 时出现问题。

我用 numpy 1.17.4 尝试过,没有问题。
当我升级到1.18.1时,我也遇到了这个错误。

正如您在错误消息中看到的,该错误是由 Holoviews 中的这一行引起的:

angles = np.linspace(p0, p1, n_conn)


创建了一个问题:
https://github.com/holoviz/holoviews/issues/4223

事实证明,已经存在一个问题:
https://github.com/holoviz/holoviews/issues/4209

关于python - 运行 Holoview 和弦图示例时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60152293/

28 4 0
文章推荐: python - 错误 : Setup iteration failed: Unidentified error, 检查门户/计算中的日志
文章推荐: javascript - jQuery - 在点击的 div 中更改 span 的 CSS
文章推荐: javascript - 用不同的颜色切换每个
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com