gpt4 book ai didi

python - 在 NumPy 中将 2D float 数组转换为 2D int 数组

转载 作者:IT老高 更新时间:2023-10-28 12:11:12 26 4
gpt4 key购买 nike

如何将 float NumPy 数组转换为 int NumPy 数组?

最佳答案

使用 astype方法。

>>> x = np.array([[1.0, 2.3], [1.3, 2.9]])
>>> x
array([[ 1. , 2.3],
[ 1.3, 2.9]])
>>> x.astype(int)
array([[1, 2],
[1, 2]])

关于python - 在 NumPy 中将 2D float 数组转换为 2D int 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10873824/

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