Python list與NumPy array 區(qū)分詳解
更新時間:2019年11月06日 11:18:31 作者:ForeverStrong
這篇文章主要介紹了Python list與NumPy array 區(qū)分詳解,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
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
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
淺談Scrapy網(wǎng)絡(luò)爬蟲框架的工作原理和數(shù)據(jù)采集
在python爬蟲中:requests + selenium 可以解決目前90%的爬蟲需求,難道scrapy 是解決剩下的10%的嗎?顯然不是。scrapy框架是為了讓我們的爬蟲更強大、更高效。接下來我們一起學(xué)習(xí)一下它吧。2019-02-02python多線程調(diào)用exit無法退出的解決方法
今天小編就為大家分享一篇python多線程調(diào)用exit無法退出的解決方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-02-02深入理解Python虛擬機中元組(tuple)的實現(xiàn)原理及源碼
在本篇文章當中主要給大家介紹?cpython?虛擬機當中針對列表的實現(xiàn),在?Python?中,tuple?是一種非常常用的數(shù)據(jù)類型,在本篇文章當中將深入去分析這一點是如何實現(xiàn)的2023-03-03Numpy 數(shù)組操作之元素添加、刪除和修改的實現(xiàn)
本文主要介紹了Numpy 數(shù)組操作之元素添加、刪除和修改的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-03-03關(guān)于keras中卷積層Conv2D的學(xué)習(xí)記錄
這篇文章主要介紹了關(guān)于keras中卷積層Conv2D的學(xué)習(xí)記錄,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-02-02