Python list与NumPy array 区分详解
作者:ForeverStrong 发布时间:2021-08-25 04:12:37
标签:Python,list,NumPy,array
1. 数据类型 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. 数据融合 (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
来源:https://blog.csdn.net/chengyq116/article/details/102921783


猜你喜欢
- 在日常工作中,除了需要从 JSON 转化为 Go 的数据结构。但往往相反的情况是:我们需要将数据以 JSON 字符串的形式发送到 Web 服
- 我们可用下面的代码将服务器端变量转换为客户端的JavaScrit变量:<%@ Language=VBScript
- 这篇论坛文章(赛迪网技术社区)着重介绍了有关SQL注入防御的防御策略及实施步骤,详细内容请参考下文:从去年下半年开始,很多网站被损害,他们在
- a=1 #1 为对象,def func(x): print('x的地址{}'.form
- html 页面<html lang="en"><head> <meta charset=&
- SQL Server对上亿的表进行排序或者上亿的表之间进行join,会导致系统失去响应。◆1.我确实做了一个很大的查询,涉及的数据表有两亿条
- 常用的代码UPDATE `表名` SET `字段名`=ceiling(rand()*500000+500000) WHERE (条件);up
- 1 分布式锁概述谈到分布式锁,必然是因为单机锁无法满足要求,在现阶段微服务多实例部署的情况下,单机语言级别的锁,无法满足并发互斥资源的安全访
- 前言上篇文章主要写了利用scapy实现ping扫描,这篇文章主要是利用scapy模块实现内网ARP扫描实现过程上篇文章中介绍了通过scapy
- 注:转载就注入出自'孤孤浪子博客'原创 http://itpro.blog.163.com 第一步 http://itpro
- 一, 当新增节点后刷新当前节点node.loaded = false;node.expand(); //新建子节点是刷新一次本节点的展开请求
- 1.先找到迁移服务器上的Data文件,我安装的是mysql5.7,默认安装的路径。那么就是在C:\ProgramData\MySQL文件里面
- 目录1.垂直(纵向)切分1.1 垂直分库 1.2 垂直分表 2. 水平(横向)切分2.1 根据数值范围2.2 根据数值取
- 建立连接在WPF当中,需要为View与ViewModel建立连接, 我们需要找到View的DataContext, 如下所示:建立连接的方式
- SCRIPT 标记 用于包含JavaScript代码. 属性 LANGUAGE&nbs
- 面向过程的程序设计把计算机程序视为一系列的命令集合,即一组函数的顺序执行。为了简化程序设计,面向过程把函数继续切分为子函数,即把大块函数通过
- 本文实例讲述了python中bisect模块用法,分享给大家供大家参考。具体方法分析如下:这个模块只有几个函数,一旦决定使用二分搜索时,立马
- 我们可以先建立一个包含文件名,文件标题的待检索文件的数据库,然后,用ADO方式来访问它,并建立记录集对象。具体代码和说明见下:
- 本文实例讲述了Python编程之序列操作。分享给大家供大家参考,具体如下:#coding=utf8''''&
- 控制的前提是已经运行Microsip.exe 首先选择文件,选择txt格式文件,一行一个手机号格式;如下点击拨打下一个