gpt4 book ai didi

python - 错误 'numpy.int32'对象不支持项目分配

转载 作者:太空宇宙 更新时间:2023-11-03 17:40:12 25 4
gpt4 key购买 nike

我收到此错误

Traceback (most recent call last):
File "C:\Users\User1\Desktop\cellh5_scripts\ewa_pnas_fate.py", line 90, in <module>
ec.combine_classifiers("Event labels combined")
File "C:\Users\User1\Desktop\cellh5_scripts\ewa_pnas_fate.py", line 53, in combine_classifiers
pnas_class[pnas_class==3] = 1
TypeError: 'numpy.int32' object does not support item assignment

通过运行代码

def combine_classifiers(self, output_name):
all_combined_classes = []
for _, (plate_name, w, p, t1, t2, track_ids, track_labels) in self.mapping[['Plate',
'Well',
'Site',
'Gene Symbol',
'siRNA ID',
'Event track ids',
'Event track labels']].iterrows():
combined_classes = []
ch5_file_handle = self.cellh5_handles[plate_name]
ch5_pos = ch5_file_handle.get_position(w, str(p))



for track_id, track_label in zip(track_ids, track_labels):

h2b_class = track_label.copy()
print(track_id)
pnas_class = ch5_pos.get_class_prediction('secondary__expanded')[track_id]['label_idx'] + 1
print(pnas_class)


inter_idx = h2b_class == 1
pnas_class[pnas_class==3] = 1
pnas_class[pnas_class==2]+=2
combined_class = h2b_class
combined_class[inter_idx] = pnas_class[inter_idx]
combined_classes.append(combined_class)

all_combined_classes.append(combined_classes)

self.mapping[output_name] = pandas.Series(all_combined_classes)

我打印 pnas_class 为 1,track_id 为 50708。我想知道代码设计者想在这部分中做什么:

inter_idx = h2b_class == 1 
pnas_class[pnas_class==3] = 1
pnas_class[pnas_class==2]+=2
combined_class = h2b_class
combined_class[inter_idx] = pnas_class[inter_idx]

如何将其更改为具有相同的含义?

最佳答案

pnas_class 是一个整数,因此您无法通过 [pnas_class==3] = 1 从整数中选择项目。

也许您正在尝试将 1 影响到 pnas_class(如果它等于 3)。在这种情况下,请尝试以下操作:

pnas_class= 1*(pnas_class == 3) + pnas_class*(pnas_class != 3 )

关于python - 错误 'numpy.int32'对象不支持项目分配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30665115/

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