You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行Python代码时遭遇numpy.core._exceptions.UFuncTypeError错误求助

Fixing the ufunc 'add' Type Mismatch Error

Hey there! Let's break down what's going on here and get this sorted quickly.

What's causing the error?

That numpy.core._exceptions.UFuncTypeError pops up because numpy can't handle adding an integer to a string. Looking at the error details:

  • The uploaded_numbers you loaded from account_number.data is a Unicode string type (dtype('<U20')), not a numeric type like int64.
  • When you try uploaded_numbers += 1, numpy's add function has no way to match a string + integer operation, hence the error.

Even if your later code uses the same logic without issues, it’s likely that in those cases the file stored numeric data—this time around, the data saved in account_number.data is a string instead.

How to fix it

You just need to convert the loaded value to a numeric type before incrementing. Here's the adjusted code:

import numpy as np
import pickle

with open(r'W:\Python\NEA Dice Project\account_number.data', 'rb') as x:
    uploaded_numbers = pickle.load(x)

# Convert the loaded value to a numpy integer type
uploaded_numbers = np.int64(uploaded_numbers)
print(uploaded_numbers)

uploaded_numbers += 1

with open(r'W:\Python\NEA Dice Project\account_number.data', 'wb') as x:
    pickle.dump(uploaded_numbers, x)

Quick verification tip

To confirm the type of your loaded data before making changes, add this line right after loading:

print(f"Loaded data type: {uploaded_numbers.dtype}")

This will show you exactly what type you’re working with, so you can double-check it’s a string before converting.

Once you run this adjusted code, the value will be stored as an integer type, so future runs using the same logic should work smoothly.

内容的提问来源于stack exchange,提问作者Sirak Vanoostende

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 01:47:29