亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將函數應用于字典值不起作用

將函數應用于字典值不起作用

ibeautiful 2023-07-11 14:54:31
我試圖使用這段代碼將包gower_matrix中的函數應用gower到字典的值:import gowerimport pandas as pdfrom itertools import chain, combinationsfrom pydataset import datafrom toolz.dicttoolz import valmapcars = data('mtcars')vnames=cars.columnsdef powerset(iterable):    "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"    s = list(iterable)    return chain.from_iterable(combinations(s, r) for r in range(1,len(s)+1))combos=list(powerset(vnames))combos=list(map(list, list(powerset(vnames))))combo_dicts = {}keys = range(len(combos))for i in keys:        combo_dicts[i] = cars[combos[i]]        gower_dicts = valmap(gower.gower_matrix, combo_dicts)但我收到以下錯誤TypeError: ufunc 'true_divide' output (typecode 'd') could not be coerced to provided output parameter (typecode 'q') according to the casting rule ''same_kind''將其應用于特定的字典項目是可行的gower.gower_matrix(combo_dicts[100])array([[0.        , 0.02173357, 0.19395797, ..., 0.12646227, 0.35655078,        0.11454861],       [0.02173357, 0.        , 0.21569154, ..., 0.12262693, 0.3348172 ,        0.10900868],       [0.19395797, 0.21569154, 0.        , ..., 0.32042024, 0.55050874,        0.10668287],       ...,       [0.12646227, 0.12262693, 0.32042024, ..., 0.        , 0.23008852,        0.21544196],       [0.35655078, 0.3348172 , 0.55050874, ..., 0.23008852, 0.        ,        0.44382587],       [0.11454861, 0.10900868, 0.10668287, ..., 0.21544196, 0.44382587,        0.        ]], dtype=float32)對這個問題有什么想法嗎?
查看完整描述

1 回答

?
慕尼黑5688855

TA貢獻1848條經驗 獲得超2個贊

根據對 的網絡搜索ufunc 'true_divide' output,似乎是在嘗試將整數值數組除以浮點值時發生錯誤(不是 Numpy 錯誤,而是幾年前更改的行為)。這似乎是gower您傳入浮點值的包的未指定要求。所以先轉換cars數據。我的猜測是,有些列包含浮點值,有些列包含整數;的測試元素combo_dicts工作正常,因為它恰好是僅從浮點列生成的。



查看完整回答
反對 回復 2023-07-11
  • 1 回答
  • 0 關注
  • 120 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號