If you want to use a list to dynamically add numpy type data, as shown in the following code, you will find that the error type error is: ‘ numpy.int64 ‘ object is not iterable
a = []
b = np.array([1,2,3])
a.extend(b[0])
a.extend(b[1])
a.extend(b[2])
print(a)
The numpy data is converted to the list type, as follows:
a = []
b = np.array([1,2,3])
a.extend(b[0].tolist())
a.extend(b[1].tolist())
a.extend(b[2].tolist())
print(a)
Error found: typeerror: ‘Int’ object is not Iterable
By printing the type of ‘B [0]. Tolist ()’, we find that the type of ‘B [0]. Tolist ()’ is’ Int ‘, that is, it does not convert’ B [0]. Tolist () ‘to list type
Then modify the code as follows, change ‘B [0]. Tolist ()’ to list type by adding a bracket []
a = []
b = np.array([1,2,3])
a.extend([b[0].tolist()])
a.extend([b[1].tolist()])
a.extend([b[2].tolist()])
print(a) #[1, 2, 3]
————————————————————————-Dividing line————————————————————————————————–
Later, I found that the following code can also be used directly:
a = []
b = np.array([1,2,3])
a.extend([b[0]])
a.extend([b[1]])
a.extend([b[2]])
print(a) #[1, 2, 3]
This is because the ‘B [0]’ is changed from numpy data type to list type by adding a bracket []
Read More:
- TypeError: ‘int’ object is not iterable
- Typeerror in Python: ‘nonetype’ object is not Iterable
- Python error: typeerror: ‘Int’ object is not subscribable
- Python reported error: typeerror:’int’object is not subscriptable
- Python 3 error typeerror: ‘dict’_ keys‘ object is not subscriptable
- TypeError: this.getOptions is not a function at Object.lessLoader
- Python error: typeerror: ‘module’ object is not callable
- Python error: typeerror: ‘Int’ object is not subscriptable
- Typeerror: ‘module’ object is not callable
- Python error prompt: typeerror: ‘builtin’_ function_ or_ method‘ object is not subscriptable
- Python custom class typeerror: ‘module’ object is not callable
- Type error: cannot unpack non Iterable non type object appears when starting Bert server in Ubuntu system
- Uncaught (in promise) TypeError: Object(…) is not a function
- Vue error in mounted hook: “typeerror: object (…) is not a function“
- Debug | AttributeError: ‘numpy.int64‘ object has no attribute ‘to_pydatetime‘
- new_lrs[:5] = lr_warm [12] TypeError: can only assign an iterable
- The background object of thymeleaf is null, which solves the problem of error when the object is empty to get the property value
- Type error at XXX ‘set’ object is not reversible
- Type error: object (…) is not a function
- ‘builtin_ function_ or_ Method ‘object is not subscriptable error