Python错题集-7:DeprecationWarning: Conversion of an array with ndim(被弃用警告)

本文分析了在使用NumPy时遇到的DeprecationWarning,关于多维数组转换为标量的问题,并提供了两种解决方法,以确保代码在新版本NumPy中的兼容性,同时展示了一个基于期望值和熵的云模型绘图示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1问题描述

DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)
  X[i] = np.random.normal(loc=Ex, scale=np.abs(Enn), size=1)

2代码详情 

import numpy as np
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

def plot_cloud_model(Ex, En, He, n, ax, label='', color = 'r',marker = 'o'):
    '''
    Ex 期望
    En 熵
    He 超熵
    n 云滴数量
    
    '''
     
    Y = np.zeros((1, n))
    np.random.seed(int(np.random.random()*100))
    X= np.random.normal(loc=En, scale=He, size=n)
    Y = Y[0]
    for i in range(n):
        np
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Pythoner研习社

整理不易,感谢金主!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值