简体   繁体   English

TypeError: concatenate() 得到了一个意外的关键字参数“dtype”

[英]TypeError: concatenate() got an unexpected keyword argument 'dtype'

I can clearly see an argument named dtype in numpy documentation .我可以在numpy 文档中清楚地看到一个名为dtype的参数。

What I can't do, is this:我不能做的是:

np.concatenate((np.array([]),np.array([3,4])),dtype=np.int64)

Which gives this error:这给出了这个错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<__array_function__ internals>", line 4, in concatenate
TypeError: concatenate() got an unexpected keyword argument 'dtype'

Without the dtype argument I get this array:没有dtype参数我得到这个数组:

>>> np.concatenate((np.array([]),np.array([3,4])))
array([3., 4.])

But I don't want those to be decimal points (float) values.但我不希望那些是小数点(浮点)值。

Why can't I use the dtype argument?为什么我不能使用dtype参数? How to make it int on concatenation even if my initial arrays had let's say float values?即使我最初的 arrays 让我们说浮点值,如何在串联时将其设为int

The documentation for dtype says: dtype文档说:

New in version 1.20.0.版本 1.20.0 中的新功能。

Version 1.20.0 has only been released in Jan 2021 . 1.20.0版本仅在 2021 年 1 月发布

Check if you have the right version installed.检查您是否安装了正确的版本。

If you look at the documentation of version 1.19 , dtype was not an argument of concatenate .如果您查看版本 1.19的文档,则dtype不是concatenate的参数。 So dtype was introduced in version 1.20.所以dtype是在 1.20 版本中引入的。

Then you can update your numpy version.然后您可以更新您的 numpy 版本。 Otherwise, if your first array is of type np.int64 and the second one contains only int , the resulting type is np.int64 .否则,如果您的第一个数组是np.int64类型,而第二个数组仅包含int ,则结果类型为np.int64

np.concatenate((np.array([], dtype=np.int64), np.array([3, 4])))

array([3, 4])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:mean()得到一个意外的关键字参数&#39;dtype&#39;#Pandas.DataFrame - TypeError: mean() got an unexpected keyword argument 'dtype' # Pandas.DataFrame mean()收到了意外的关键字参数&#39;dtype&#39;! - mean() got an unexpected keyword argument 'dtype'! MoviePy:linspace() 得到了一个意外的关键字参数“dtype” - MoviePy: linspace() got an unexpected keyword argument 'dtype' TypeError:得到一个意外的关键字参数 - TypeError: got an unexpected keyword argument 类型错误:to_list_if_array() 得到了一个意外的关键字参数“convert_dtype” - TypeError: to_list_if_array() got an unexpected keyword argument 'convert_dtype' E TypeError: read_sql_query() got an unexpected keyword argument 'dtype' - E TypeError: read_sql_query() got an unexpected keyword argument 'dtype' 类型错误:function() 得到了一个意外的关键字参数“njobs” - TypeError: function() got an unexpected keyword argument 'njobs' 类型错误:_log() 得到了意外的关键字参数“stacklevel” - TypeError: _log() got an unexpected keyword argument 'stacklevel' 类型错误:有一个意外的关键字参数“条目” - TypeError: got an unexpected keyword argument 'entry' TypeError:editProfile()得到了意外的关键字参数“ obj” - TypeError: editProfile() got an unexpected keyword argument 'obj'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM