TypeError: data type not understood

如何使用Python产生一个数组,数组的长度为1024,数组的元素全为0?

很简单啊, 使用zeros(1024) 即可实现!

如何产生一个2×1024的全0矩阵呢?是否是zeros(2,1024) ?

若是上述这种写法就会出现 TypeError: data type not understood 这种错误; 

正确的写法是 zeros((2,1024)),python的二维数据表示要用二层括号来进行表示。

import tensorflow as tf

import numpy as np

matrix_1=np.zeros((3,4))

matrix_1

array([[ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.]])

猜你喜欢

转载自blog.csdn.net/qq_40213457/article/details/80644442