您好,登錄后才能下訂單哦!
這篇文章主要介紹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)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道!
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。