ValueError:需要至少一个数组来堆叠

问题描述 投票:0回答:1

我正在使用 Hyperspy 官方网站上的代码在图像堆栈上测试高斯滤波器。我不断收到错误消息“ValueError:需要至少一个数组来堆叠”。

%matplotlib qt

import hyperspy.api as hs
import numpy as np
import scipy.ndimage

im = hs.signals.Signal2D(np.random.random((10, 64, 64)))
im.map(scipy.ndimage.gaussian_filter, sigma=2.5)

ValueError:需要至少一个数组来堆叠

追溯信息 -------------------------------------------------- --------------------------

ValueError                                Traceback (most recent call last)

<ipython-input-2-37abd5454503> in <module>
      1 im = hs.signals.Signal2D(np.random.random((10, 64, 64)))
----> 2 im.map(scipy.ndimage.gaussian_filter, sigma=2.5)
      3 

f:\programming\python\projects\hyperspy\lib\site-packages\hyperspy\signal.py in map(self, function, show_progressbar, parallel, inplace, ragged, **kwargs)
   3931                                     parallel=parallel, inplace=inplace,
   3932                                     ragged=ragged,
-> 3933                                     **kwargs)
   3934         if inplace:
   3935             self.events.data_changed.trigger(obj=self)

f:\programming\python\projects\hyperspy\lib\site-packages\hyperspy\signal.py in _map_iterate(self, function, iterating_kwargs, show_progressbar, parallel, ragged, inplace, **kwargs)
   4076         if not ragged:
   4077             sig_shape = () if shapes[0] == (1,) else shapes[0]
-> 4078             res_data = np.stack(res_data.flat).reshape(
   4079                 self.axes_manager._navigation_shape_in_array + sig_shape)
   4080         res = map_result_construction(self, inplace, res_data, ragged,

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

f:\programming\python\projects\hyperspy\lib\site-packages\numpy\core\shape_base.py in stack(arrays, axis, out)
    419     arrays = [asanyarray(arr) for arr in arrays]
    420     if not arrays:
--> 421         raise ValueError('need at least one array to stack')
    422 
    423     shapes = {arr.shape for arr in arrays}

ValueError: need at least one array to stack
python pycharm jupyter hyperspy
1个回答
-1
投票

这在当前版本的 hyperspy (1.7.2) 和 numpy (1.23.3) 中工作得很好:可能是某个地方的错误,此后已修复,或者依赖项不兼容。

© www.soinside.com 2019 - 2024. All rights reserved.