TypeError: Cannot interpret ‘4‘ as a data type

TypeError: Cannot interpret ‘4’ as a data type

问题:

在写代码时,self.observations = np.zeros((self.max_size, state_dim),其中self.max_sizestate_dim分别是两个参数,结果报错:TypeError: Cannot interpret '4' as a data type

分析:

numpy.zeros()参数为:numpy.zeros(shape, dtype=float, order='C', *, like=None)
TypeError: Cannot interpret ‘4‘ as a data type_第1张图片

关于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))

你可能感兴趣的:(numpy学习,numpy)