![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python
澍yeah
知识的搬运工
展开
-
Python中引用MATLAB保存数据
我从MATLAB中获得96*3136的矩阵数据C时,保存为data.mat文件,我在Python中调用这个文件的时候要用data【C】才是这个96*3136的矩阵原创 2018-05-29 08:52:25 · 246 阅读 · 0 评论 -
Python abs() 函数
Python abs() 函数描述:abs() 函数返回数字的绝对值。语法:以下是 abs() 函数的语法:abs(x) 参数:x 数值表达式返回值:函数返回 x (数字)的绝对值。实例:(1)# -*- coding: UTF-8 -*-x = -23 print abs(x)print abs(-34)...转载 2018-07-19 10:37:29 · 3299 阅读 · 0 评论 -
Could not find a version that satisfies the requirement pytz (from matplotlib->svmpy) (from versio
pip install svmpy出现的错误 error: Could not find a version that satisfies the requirement pytz (from matplotlib->svmpy) (from versions: )No matching distribution found for pytz (from matplotlib-&...原创 2018-07-28 20:32:41 · 8476 阅读 · 0 评论 -
Python、C++学习的网站
3.pythonhttp://www.runoob.com/python/att-string-rstrip.html原创 2018-07-26 14:16:50 · 134 阅读 · 0 评论 -
scipy.ndimage.interpolation.zoom
参考:https://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.ndimage.interpolation.zoom.html功能是缩放数组,即使用order顺序的样条插值来缩放数组。scipy.ndimage.interpolation.zoom(input, zoom, output=None, order=3,...原创 2018-07-26 15:11:44 · 13586 阅读 · 0 评论 -
python 读写二进制文件
一个字节8位,4个字节32位,也就是2^32;Python创建并把数据写入二进制文件import structf = open('n.dat', 'wb')a = struct.pack(‘I’, 0)#I是i的大写f.write(a) 可参考:https://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb4931...原创 2018-07-21 19:12:00 · 1798 阅读 · 0 评论 -
TypeError: Non-character array cannot be interpreted as character buffer.
把fileObject.write(np.min(b))改为fileObject.write(str(np.min(b)))原创 2018-08-03 09:55:41 · 1234 阅读 · 0 评论 -
python︱numpy、array——高级matrix(替换、重复、格式转换、切片)
参考:https://blog.csdn.net/sinat_26917383/article/details/52290505# 属性ndarray.shape: 多維陣列的大小(形狀)ndarray.ndim: 多維陣列的維度ndarray.itemsize: 陣列當中元素的大小(佔幾個 byte)ndarray.nbytes: 整個陣列所有元素的大小總計ndarray.T: ...转载 2018-09-23 17:23:51 · 808 阅读 · 0 评论 -
Python 读取显示保存图片----python skimage图像处理
转载:https://blog.csdn.net/weixin_41500849/article/details/80366991基于python脚本语言开发的数字图片处理包,比如PIL,Pillow, opencv, scikit-image等。PIL和Pillow只提供最基础的数字图像处理,功能有限;opencv实际上是一个c++库,只是提供了python接口,更新速度非常慢。scikit...转载 2018-09-13 21:22:00 · 8154 阅读 · 1 评论 -
h5py文件使用
转:https://blog.csdn.net/qq_34859482/article/details/80115237h5py文件介绍、写入数据、读取数据、存储字符串和ASCII,详解上面博客转载 2018-09-13 21:48:00 · 3025 阅读 · 0 评论 -
Python 中各种imread函数的区别与联系
详解见:https://blog.csdn.net/renelian1572/article/details/78761278#encoding=utf8from PIL import Imageimport numpy as npimport cv2import matplotlib.pyplot as plt # plt 用于显示图片import matplotlib.imag...转载 2018-09-14 09:56:45 · 508 阅读 · 0 评论 -
ImportError: No module named '‘’
1、 ImportError: No module named 'scipy'sudo apt-get install python-scipy2、ImportError: No module named h5py sudo apt-get install libhdf5-devsudo apt-get install python-h5py3、ImportError:...原创 2018-09-14 09:57:07 · 733 阅读 · 0 评论 -
Python 中 .format()用法
Python中格式化输出字符串使用format()函数, 字符串即类, 可以使用方法;Python是完全面向对象的语言, 任何东西都是对象;字符串的参数使用{NUM}进行表示,0, 表示第一个参数,1, 表示第二个参数, 以后顺次递加;使用":", 指定代表元素需要的操作, 如":.3"小数点三位, ":8"占8个字符空间等;还可以添加特定的字母, 如:'b' - 二进制. 将...转载 2018-09-14 14:25:05 · 5721 阅读 · 0 评论 -
tf.summary用法
转:https://blog.csdn.net/hongxue8888/article/details/797536791、tf.summary.scalar用来显示标量信息,其格式为:tf.summary.scalar(name, tensor, collections=None)1例如:tf.summary.scalar('mean', mean)一般在画loss,ac...转载 2018-09-14 14:37:21 · 1226 阅读 · 0 评论 -
numpy.dot(
numpy.dot(a, b, out=None) 计算两个数组的乘积。对于二维数组来说,dot()计算的结果就相当于矩阵乘法。对于一维数组,它计算的是两个向量的点积。 对于N维数组,它是a的最后一维和b的倒数第二维和的积:dot(a, b)[i,j,k,m] = sum(a[i,j,:] * b[k,:,m])参数: a : array_like b : array_like out : nda...转载 2018-07-13 13:45:55 · 936 阅读 · 0 评论 -
python图像操作
Python 里面最常用的图像操作库是Image library(PIL),功能上,虽然还不能跟Matlab比较,但是还是比较强大的,废话补多少,写点记录笔记。1. 首先需要导入需要的图像库:import Image2. 读取一张图片:im=Image.open(‘/home/Picture/test.jpg’)3. 显示一张图片:im.show()4. 保存图片:im.save(“save.gi...转载 2018-07-13 09:48:23 · 167 阅读 · 0 评论 -
squeeze()和abs()、a.shape
1、abs()是得到绝对值eg:>>abs(-1)>>12、a如果是个矩阵,a.shape得到的是a的维度,若a是2*2,则a.shape得到(2,2)3、numpy.squeeze(a, axis=None)squeeze()函数的功能是:从矩阵shape中,去掉维度为1的。例如一个矩阵是的shape是(5, 1),使用过这个函数后...原创 2018-07-24 11:18:34 · 261 阅读 · 0 评论 -
Python中把矩阵保存为图片
import scipyscipy.misc.imsave('a.jpg', a)原创 2018-05-29 11:15:14 · 14377 阅读 · 3 评论 -
python换维
data是 在matlab上得到的56*56*96的三维矩阵,载入到Python中是字典:data转换维矩阵data【‘B’】:把56*56*96变为3136*96:-1是所有列,a.shape[o]=3136;a.shape[1]=96;原创 2018-06-02 15:48:48 · 243 阅读 · 0 评论 -
assert()函数用法总结
assert()函数用法总结 assert宏的原型定义在<assert.h>中,其作用是如果它的条件返回错误,则终止程序执行,原型定义:#include <assert.h>void assert( int expression ); assert的作用是现计算表达式 expression ,如果其值为假(即为0),那么它先向stderr打印一条出错信息,然后通过调用...转载 2018-06-30 15:46:06 · 575 阅读 · 0 评论 -
session.run()
转:https://blog.csdn.net/u012436149/article/details/52908692session.run()【2016.12.28.错误更新:之前对sess.run([train_op, loss])理解有误,已更新成正确版本】session.run([fetch1, fetch2])关于 session.run([fetch1, fetch2]),请看http...转载 2018-06-30 17:11:48 · 11821 阅读 · 0 评论 -
读取并显示图片
转自:http://www.cnblogs.com/yinxiangnan-charles/p/5928689.html在 python 中除了用 opencv,也可以用 matplotlib 和 PIL 这两个库操作图片。本人偏爱 matpoltlib,因为它的语法更像 matlab。一、matplotlib1. 显示图片import matplotlib.pyplot as plt # plt...转载 2018-07-16 12:58:45 · 270 阅读 · 0 评论 -
把图片变成16比特
当值大于255的时候,可以把图片矩阵存为16比特深度的,平常图片比特深度为8,即0-255,现在变为0-65535:图片为RGB3维矩阵,如果只有一维,则把2-3维变为0a=scipy.misc.imread(file_name).astype(np.uint16) a[:,:,1:3]=0 a[0:1,0:1,0:1]=53021 a[0:1,1:2,0...原创 2018-07-16 14:19:37 · 1041 阅读 · 0 评论 -
txt保存的样本转为矩阵, numpy:将数组保存到txt文件中将矩阵转换为图片
1、读取指定文件内容[python] view plain copydef file2matric(filename): """将txt文件的样本值存储到数组中 """ with open(filename) as file_object: lines = file_object.readlines()#读取文件内容,返回存储每行的字符串列表 len...转载 2018-06-28 15:54:34 · 1553 阅读 · 0 评论 -
data.py对TXT文件做处理,变为矩阵
# coding: utf-8import numpy as npfrom PIL import Imagefrom scipy import ndimagefrom scipy import miscdef file2matric(a): """将txt文件的样本值存储到数组中 """ with open(a) as file_object: ...原创 2018-07-17 14:36:35 · 337 阅读 · 0 评论 -
批量文件处理
调用.sh文件: bash xxx.shbash.sh:for ((i=0;i<10511;i++))do (python z.py -m test -f images/11.jpg -n $i)doneexit 0.py文件中和bash有关的内容 import numpy as np import scipy import argpars...原创 2018-07-17 14:40:48 · 418 阅读 · 0 评论 -
misc.imresize
转:https://blog.csdn.net/wenqiwenqi123/article/details/79306611这个函数如它名字一般,就是拿来重新调整图片的形状的。这样说比较抽象,直接看代码:import scipy.miscimport numpy as np def imread(path): img = scipy.misc.imread(path).astype(np....转载 2018-07-12 10:23:51 · 1501 阅读 · 5 评论 -
Python矩阵
>>> n = np.arange(0, 30, 2)>>> narray([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28])>>> n=n.reshape(3,5)>>> narray([[ 0, 2, 4, 6, 8], [10, ...原创 2018-07-12 10:52:56 · 1370 阅读 · 0 评论 -
矩阵连接
1. np.concatenate连接矩阵,然后reshapeimport numpy as npx1 = np.array([[1,1], [1,1]])x2 = np.array([[2,2],[2,2]])x3 = np.concatenate((x1,x2))x3 = x3.reshape((x1.shape[0],2)+x1.shape[1:])print x3.sh...转载 2018-07-12 10:59:13 · 2417 阅读 · 0 评论 -
Numpy 中多维数组的切片操作与 Python
切片(slicing)操作Numpy 中多维数组的切片操作与 Python 中 list 的切片操作一样,同样由 start, stop, step 三个部分组成import numpy as nparr = np.arange(12)print 'array is:', arrslice_one = arr[:4]print 'slice begins at 0 and ends a...转载 2018-07-12 11:13:33 · 17145 阅读 · 0 评论 -
Python中rgb与ycbcr互转
mat = np.array( [[ 65.481, 128.553, 24.966 ], [-37.797, -74.203, 112.0 ], [ 112.0, -93.786, -18.214]])mat_inv = np.linalg.inv(mat)offset = np.array([16, 128, 128])def rgb2ycbcr(rg...原创 2018-09-22 17:45:07 · 6639 阅读 · 0 评论