社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

U12-Forward

U12-Forward 最近创建的主题
U12-Forward 最近回复了
4 年前
回复了 U12-Forward 创建的主题 » 用Numpy Python编写数组

这样比较好 np.vectorize :

format_number = lambda n: n if n % 1 else int(n)
for count, formater in enumerate([a, b, c]):
    formater[formater < 0] = 0
    formatter = np.vectorize(format_number)(formater)
    print(formater.tolist())

要修复代码,请执行以下操作:

format_number = lambda n: n if n % 1 else int(n)
for count,formater in enumerate([a, b, c]):
    formater = list(map(lambda n: 0 if n < 0 else format_number(n), formater))
    print(formater)

两种输出:

[2323, 34, 12, 0, 12, 4, 0, 0, 0, 11, 0]
[12, 0, 0, 0, 0]
[23, 45, 3, 13, 0, 5]