tensorflow: 类numpy的api映射表

来源:互联网 发布:范冰冰演技 知乎 编辑:程序博客网 时间:2024/06/14 06:28
Annotations tensorflow api numpy api 建立全零张量 tf.zeros(shape=(H, W), dtype=tf.float32) np.zeros(shape=(H, W), dtype=np.float32) 建立全一张量 tf.ones(shape=(H, W), dtype=tf.float32) np.ones(shape=(H, W), dtype=np.float32) 元素乘法 tf.mul(A, B) A * B 矩阵乘法 tf.matmul(A, B) np.dot(A * B) 张量形状 tf.shape(A)、A.get_shape() A.shape() 塑形 tf.reshape(A, (H, W)) np.reshape(A, (H, W)) 浮点化 tf.to_float(A) float(A) 整型化 tf.to_int32(A)、tf.to_int64(A) int(A) 张量的元素数量 tf.size(A) np.size(A) 张量的阶 tf.rank(A) np.ndim(A) 拼接 tf.concat(A, B) np.concatenate(A, B) 求和 tf.reduce_sum(A, axis=0) np.ndarray.sum(A, axis=0) 互相转换 tf.convert_to_tensor(A)

原创粉丝点击