Python list與NumPy array 區(qū)分詳解
1. 數(shù)據(jù)類型 type()
#!/usr/bin/env python # -*- coding: utf-8 -*- # Yongqiang Cheng from __future__ import absolute_import from __future__ import print_function from __future__ import division import os import sys sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..') current_directory = os.path.dirname(os.path.abspath(__file__)) import numpy as np # import tensorflow as tf import cv2 import time print(16 * "++--") print("current_directory:", current_directory) PIXEL_MEAN = [123.68, 116.779, 103.939] # R, G, B. In TensorFlow, channel is RGB. In OpenCV, channel is BGR. print("Python list") print("PIXEL_MEAN:", PIXEL_MEAN) print("type(PIXEL_MEAN):", type(PIXEL_MEAN)) print("type(PIXEL_MEAN[0]):", type(PIXEL_MEAN[0]), "\n") PIXEL_MEAN_array = np.array(PIXEL_MEAN) print("NumPy array") print("PIXEL_MEAN_array:", PIXEL_MEAN_array) print("type(PIXEL_MEAN_array):", type(PIXEL_MEAN_array)) print("type(PIXEL_MEAN_array[0]):", type(PIXEL_MEAN_array[0])) print("PIXEL_MEAN_array.dtype:", PIXEL_MEAN_array.dtype)
/usr/bin/python2.7 /home/strong/tensorflow_work/R2CNN_Faster-RCNN_Tensorflow/yongqiang.py --gpu=0 ++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++-- current_directory: /home/strong/tensorflow_work/R2CNN_Faster-RCNN_Tensorflow Python list PIXEL_MEAN: [123.68, 116.779, 103.939] type(PIXEL_MEAN): <type 'list'> type(PIXEL_MEAN[0]): <type 'float'> NumPy array PIXEL_MEAN_array: [123.68 116.779 103.939] type(PIXEL_MEAN_array): <type 'numpy.ndarray'> type(PIXEL_MEAN_array[0]): <type 'numpy.float64'> PIXEL_MEAN_array.dtype: float64 Process finished with exit code 0
2. 數(shù)據(jù)融合 (data fusion)
#!/usr/bin/env python # -*- coding: utf-8 -*- # Yongqiang Cheng from __future__ import absolute_import from __future__ import print_function from __future__ import division import os import sys sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..') current_directory = os.path.dirname(os.path.abspath(__file__)) import numpy as np # import tensorflow as tf import cv2 import time print(16 * "++--") print("current_directory:", current_directory) PIXEL_MEAN = [123.68, 116.779, 103.939] # R, G, B. In TensorFlow, channel is RGB. In OpenCV, channel is BGR. print("Python list") print("PIXEL_MEAN:", PIXEL_MEAN) print("type(PIXEL_MEAN):", type(PIXEL_MEAN)) print("type(PIXEL_MEAN[0]):", type(PIXEL_MEAN[0]), "\n") PIXEL_MEAN_array = np.array(PIXEL_MEAN) print("NumPy array") print("PIXEL_MEAN_array:", PIXEL_MEAN_array) print("type(PIXEL_MEAN_array):", type(PIXEL_MEAN_array)) print("type(PIXEL_MEAN_array[0]):", type(PIXEL_MEAN_array[0])) print("PIXEL_MEAN_array.dtype:", PIXEL_MEAN_array.dtype, "\n") image_array = np.array( [[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], [[21, 22, 23], [24, 25, 26], [27, 28, 29], [30, 31, 32]]]) print("image_array:", image_array) print("type(image_array):", type(image_array)) print("type(image_array[0]):", type(image_array[0])) print("image_array.dtype:", image_array.dtype, "\n") image_array_fusion = image_array + np.array(PIXEL_MEAN) print("image_array_fusion:", image_array_fusion) print("type(image_array_fusion):", type(image_array_fusion)) print("type(image_array_fusion[0]):", type(image_array_fusion[0])) print("image_array_fusion.dtype:", image_array_fusion.dtype)
/usr/bin/python2.7 /home/strong/tensorflow_work/R2CNN_Faster-RCNN_Tensorflow/yongqiang.py --gpu=0 ++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++-- current_directory: /home/strong/tensorflow_work/R2CNN_Faster-RCNN_Tensorflow Python list PIXEL_MEAN: [123.68, 116.779, 103.939] type(PIXEL_MEAN): <type 'list'> type(PIXEL_MEAN[0]): <type 'float'> NumPy array PIXEL_MEAN_array: [123.68 116.779 103.939] type(PIXEL_MEAN_array): <type 'numpy.ndarray'> type(PIXEL_MEAN_array[0]): <type 'numpy.float64'> PIXEL_MEAN_array.dtype: float64 image_array: [[[ 1 2 3] [ 4 5 6] [ 7 8 9] [10 11 12]] [[21 22 23] [24 25 26] [27 28 29] [30 31 32]]] type(image_array): <type 'numpy.ndarray'> type(image_array[0]): <type 'numpy.ndarray'> image_array.dtype: int64 image_array_fusion: [[[124.68 118.779 106.939] [127.68 121.779 109.939] [130.68 124.779 112.939] [133.68 127.779 115.939]] [[144.68 138.779 126.939] [147.68 141.779 129.939] [150.68 144.779 132.939] [153.68 147.779 135.939]]] type(image_array_fusion): <type 'numpy.ndarray'> type(image_array_fusion[0]): <type 'numpy.ndarray'> image_array_fusion.dtype: float64 Process finished with exit code 0
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
在Python的Django框架中編寫錯(cuò)誤提示頁(yè)面
這篇文章主要介紹了在Python的Django框架中編寫錯(cuò)誤提示頁(yè)面,包括傳統(tǒng)的404頁(yè)面和設(shè)置連接中斷警告等,需要的朋友可以參考下2015-07-07使用Python標(biāo)準(zhǔn)庫(kù)中的wave模塊繪制樂(lè)譜的簡(jiǎn)單教程
這篇文章主要介紹了使用Python標(biāo)準(zhǔn)庫(kù)中的wave模塊繪制樂(lè)譜,涉及到了numpy模塊和坐標(biāo)的可視化運(yùn)用,用到了需要的朋友可以參考下2015-03-03淺談Scrapy網(wǎng)絡(luò)爬蟲框架的工作原理和數(shù)據(jù)采集
在python爬蟲中:requests + selenium 可以解決目前90%的爬蟲需求,難道scrapy 是解決剩下的10%的嗎?顯然不是。scrapy框架是為了讓我們的爬蟲更強(qiáng)大、更高效。接下來(lái)我們一起學(xué)習(xí)一下它吧。2019-02-02python多線程調(diào)用exit無(wú)法退出的解決方法
今天小編就為大家分享一篇python多線程調(diào)用exit無(wú)法退出的解決方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-02-02深入理解Python虛擬機(jī)中元組(tuple)的實(shí)現(xiàn)原理及源碼
在本篇文章當(dāng)中主要給大家介紹?cpython?虛擬機(jī)當(dāng)中針對(duì)列表的實(shí)現(xiàn),在?Python?中,tuple?是一種非常常用的數(shù)據(jù)類型,在本篇文章當(dāng)中將深入去分析這一點(diǎn)是如何實(shí)現(xiàn)的2023-03-03Numpy 數(shù)組操作之元素添加、刪除和修改的實(shí)現(xiàn)
本文主要介紹了Numpy 數(shù)組操作之元素添加、刪除和修改的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-03-03關(guān)于keras中卷積層Conv2D的學(xué)習(xí)記錄
這篇文章主要介紹了關(guān)于keras中卷積層Conv2D的學(xué)習(xí)記錄,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-02-02Python實(shí)現(xiàn)自定義讀寫分離代碼實(shí)例
這篇文章主要介紹了Python實(shí)現(xiàn)自定義讀寫分離代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-11-11python按照多個(gè)字符對(duì)字符串進(jìn)行分割的方法
這篇文章主要介紹了python按照多個(gè)字符對(duì)字符串進(jìn)行分割的方法,涉及Python中正則表達(dá)式匹配的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-03-03