gpt4 book ai didi

python - Numpy matmul - 当前不支持对象数组

转载 作者:行者123 更新时间:2023-11-28 20:33:00 25 4
gpt4 key购买 nike

当我在代码中的某行调用 np.matmul 时出现此错误。这是我在解决 python 调试器错误时得到的信息:

> /home/marcos/Desktop/Machine_Learning_for_Alzheimer/createDataset.py(185)nonlinear_expand()
-> rsrvr_input = matmul(src_dataset, array(input_weights.todense()))
(Pdb) type(src_dataset)
<class 'numpy.ndarray'>
(Pdb) type(array(input_weights.todense()))
<class 'numpy.ndarray'>
(Pdb) matmul(array([2]),array([2]))
4
(Pdb) src_dataset.shape
(59, 36045)
(Pdb) array(input_weights.todense()).shape
(36045, 5000)
(Pdb) src_dataset
array([[0.34718266129493713, 0.43048959970474243, 0.31317993998527527, ...,
0.08795060217380524, 0.4226779639720917, 0.12640206515789032],
[0.333339124917984, 0.30553877353668213, 0.33829280734062195, ...,
0.1962795853614807, 0.5640064477920532, 0.13812369108200073],
[0.31267049908638, 0.29710978269577026, 0.3062109649181366, ...,
0.23275987803936005, 0.5658718943595886, 0.18722198903560638],
...,
[0.3225921392440796, 0.38019028306007385, 0.29140061140060425, ...,
0.20768669247627258, 0.43566110730171204, 0.13893568515777588],
[0.33491265773773193, 0.5155439972877502, 0.3620935082435608, ...,
0.09752997010946274, 0.18645673990249634, 0.09302680939435959],
[0.31085047125816345, 0.3607252836227417, 0.32846760749816895, ...,
0.18291841447353363, 0.4967271387577057, 0.17849059402942657]], dtype=object)
(Pdb) type(array([2]))
<class 'numpy.ndarray'>
(Pdb) matmul(src_dataset, array(input_weights.todense()))
*** TypeError: Object arrays are not currently supported

所以,问题就在于此。我清楚地将两个 numpy.ndarrays 相乘,它们的大小正确。我在执行 matmul(array([2]),array([2])) 时与我正在做的事情有什么不同?

谢谢!!

最佳答案

问题是您的数组被 numpy 视为包含对象 而不是数字(即dtype=object 参数)。您需要通过执行类似的操作来转换它们

data = data.astype(float)

关于python - Numpy matmul - 当前不支持对象数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51521063/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com