python Tensor和Array對比分析
如下所示:
區(qū)別 | Array | Tensor |
---|---|---|
類型 | uint8,float32系列 | {} |
各類型相互轉(zhuǎn)換 | uint8轉(zhuǎn)float64:image = image * (2. / 255.) - 1 float64轉(zhuǎn)uint8:image.astype(np.uint8) | {} |
擴充維度 | image[np.newaxis, :] | tf.expand_dims(image,axis=0) |
數(shù)組拼接 | np.concatenate([image, image], axis=0) | tf.concat([frame,frame],axis=0) |
相互轉(zhuǎn)換 | image.eval() | tf.convert_to_tensor(image) |
拼接 | np.concat, np.concatenate, np.stack, image.append等 | tf.stack, tf.concat |
##array的一些操作
1、獲取shape:score.shape #(1, 257, 257)
2、轉(zhuǎn)換成list:score.get_shape().as_list() #[1, 257, 257]
3、list前再擴充一維: [1] + score.get_shape().as_list() #[1, 1, 257, 257]
4、x_crops是(1, 3, 255, 255, 3),將前兩維合并:
x_crops = tf.reshape(x_crops, [x_crops_shape[0] * x_crops_shape[1]] + x_crops_shape[2: ])
5、numpy數(shù)組堆疊
z.shape本來是(1,127,127,3),想要堆疊成(3,127,127,3)
np.stack([z_crops_hog,z_crops_hog,z_crops_hog])后,變成了(3, 1, 127, 127, 3),
vstack 按行堆疊
hstack 按列堆疊
以上這篇python Tensor和Array對比分析就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python sqlparse解析SQL表血緣追蹤實現(xiàn)
這篇文章主要為大家介紹了Python sqlparse解析SQL表血緣追蹤實現(xiàn),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-10-10