argmin() got an unexpected keyword argument 'keepdims'
时间: 2023-11-20 12:06:22 浏览: 56
根据提供的引用内容,可以得知发生了TypeError错误,错误信息为'argmin() got an unexpected keyword argument 'keepdims''。这个错误通常是由于使用了不支持keepdims参数的函数而导致的。keepdims参数是在numpy 1.8版本中引入的,如果你的numpy版本低于1.8,则不支持该参数。解决这个问题的方法是升级numpy版本或者删除keepdims参数。
以下是两种解决方法:
1.升级numpy版本
```python
pip install --upgrade numpy
```
2.删除keepdims参数
```python
import numpy as np
a = np.array([[3,7,5],[8,4,3],[2,4,9]])
print(np.argmin(a, axis=0)) # 删除keepdims参数后,输出:[2 1 1]
```
相关问题
TypeError: __init__() got an unexpected keyword argument 'defaultColWidthPt'
TypeError: __init__() got an unexpected keyword argument 'defaultColWidthPt'是一个错误提示,意味着在使用__init__()函数时传入了一个未预期的关键字参数'defaultColWidthPt'。这个错误通常发生在使用第三方库或自定义类时,传入了不支持的参数。
以下是两种可能的解决方法:
1. 检查参数名是否正确:首先,确保你正确地拼写了参数名'defaultColWidthPt'。如果你使用的是第三方库或自定义类,请查阅相关文档以确认参数名是否正确。
2. 检查库或类的版本:有时,这个错误可能是由于使用了不兼容的库或类版本引起的。请确保你使用的是与你代码兼容的库或类的最新版本。
范例:
```python
# 示例代码
class MyClass:
def __init__(self, arg1, arg2):
self.arg1 = arg1
self.arg2 = arg2
# 创建实例时传入了未预期的关键字参数'defaultColWidthPt'
my_obj = MyClass(arg1='value1', arg2='value2', defaultColWidthPt=10)
# 上述代码会触发TypeError: __init__() got an unexpected keyword argument 'defaultColWidthPt'
```
__init__() got an unexpected keyword argument 'bounds'
This error occurs when the `bounds` argument is used in the `__init__()` method of a class that doesn't accept it. The `bounds` argument is typically used in optimization functions to specify constraints on the variables being optimized.
To fix this error, you can either remove the `bounds` argument from the `__init__()` method or modify the class to accept the `bounds` argument. For example:
```
class MyClass:
def __init__(self, arg1, arg2):
# do something with arg1 and arg2
pass
# If you try to create an instance of MyClass with bounds parameter
obj = MyClass(arg1=1, arg2=2, bounds=[0, 1])
# You will get the error: __init__() got an unexpected keyword argument 'bounds'
# To fix this error, you can modify the class to accept the bounds parameter:
class MyClass:
def __init__(self, arg1, arg2, bounds=None):
# do something with arg1 and arg2
self.bounds = bounds
# Now you can create an instance of MyClass with bounds parameter
obj = MyClass(arg1=1, arg2=2, bounds=[0, 1])
# This will work without any errors
```
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)