脾气暴躁的天花板和地板“出"争论 [英] Numpy Ceil and Floor "out" Argument

查看:85
本文介绍了脾气暴躁的天花板和地板“出"争论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从NumPy中有关ceil的文档numpy.ceil函数带有两个参数,第二个参数是out.文档未说明此out参数的作用,但我假设您可以设置此函数返回的输出类型,但我无法使其正常工作:

From the NumPy docs for ceil , the numpy.ceil function takes two arguments, the second being out. The docs don't say what this out parameter does but I assume you can set the output type this function returns, but I cannot get it to work:

In [107]: np.ceil(5.5, 'int')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-107-c05bcf9f1522> in <module>()
----> 1 np.ceil(5.5, 'int')

TypeError: return arrays must be of ArrayType

In [108]: np.ceil(5.5, 'int64')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-108-0937d09b0433> in <module>()
----> 1 np.ceil(5.5, 'int64')

TypeError: return arrays must be of ArrayType

是否可以使用此参数使np.ceil返回整数?

Is it possible to use this argument to make np.ceil return an integer?

谢谢.

推荐答案

out是输出 array (必须与输入的形状相同).

out is the output array (which must have the same shape as the input).

如果将其构造为所需的dtype,则将是您得到的dtype:

If you construct it to be of the desired dtype, that'll be the dtype you get:

>>> arr = np.array([5.5, -7.2])
>>> out = np.empty_like(arr, dtype=np.int64)
>>> np.ceil(arr, out)
array([ 6, -7], dtype=int64)
>>> out
array([ 6, -7], dtype=int64)

这篇关于脾气暴躁的天花板和地板“出"争论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆