python Tensor和Array對(duì)比分析
如下所示:
區(qū)別 | Array | Tensor |
---|---|---|
類(lèi)型 | uint8,float32系列 | {} |
各類(lèi)型相互轉(zhuǎn)換 | uint8轉(zhuǎn)float64:image = image * (2. / 255.) - 1 float64轉(zhuǎn)uint8:image.astype(np.uint8) | {} |
擴(kuò)充維度 | 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前再擴(kuò)充一維: [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本來(lái)是(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對(duì)比分析就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
python excel轉(zhuǎn)換csv代碼實(shí)例
這篇文章主要介紹了python excel轉(zhuǎn)換csv代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-08-08Python sqlparse解析SQL表血緣追蹤實(shí)現(xiàn)
這篇文章主要為大家介紹了Python sqlparse解析SQL表血緣追蹤實(shí)現(xiàn),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10在pycharm中實(shí)現(xiàn)刪除bookmark
今天小編就為大家分享一篇在pycharm中實(shí)現(xiàn)刪除bookmark,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-02-02python實(shí)戰(zhàn)之德州撲克第二步-判斷牌型
這篇文章主要介紹了python實(shí)戰(zhàn)之德州撲克第二步-判斷牌型,文中有非常詳細(xì)的代碼示例,對(duì)正在學(xué)習(xí)python的小伙伴們有非常好的幫助,需要的朋友可以參考下2021-04-04