TypeError: Cannot interpret ‘4’ as a data type
问题:
在写代码时,self.observations = np.zeros((self.max_size, state_dim)
,其中self.max_size
和state_dim
分别是两个参数,结果报错:TypeError: Cannot interpret '4' as a data type
分析:
numpy.zeros()
参数为:numpy.zeros(shape, dtype=float, order='C', *, like=None)
关于shape的介绍:
shapeint or tuple of ints
Shape of the new array, e.g., (2, 3) or 2.
解决:
因此对于多维的应该加括号:self.observations = np.zeros((self.max_size, state_dim))