1. if __name__ == '__main__': #程序中有这句,就表示如果直接执行本程序,可以无视这句.
但如果import本程序,这句里面的都不执行,只执行前面的
2.python的类为什么要有self? 即通过类调用方法.
class animal:
def dog(self):
print('this is a dog')
p = animal()
p.dog() #------python中带了self这里相当于p.animal.dog() 也就是谁调用我,我就指向谁.this.name = name
3.reshape
举个简单的例子,要记住,python默认是按行取元素
c = np.array([[1,2,3],[4,5,6]])
输出:
[[1 2 3]
[4 5 6]]
我们看看不同的reshape
print '改成2行3列:'
print c.reshape(2,3)
print '改成3行2列:'
print c.reshape(3,2)
print '我也不知道几行,反正是1列:'
print c.reshape(-1,1)
print '我也不知道几列,反正是1行:'
print c.reshape(1,-1)
print '不分行列,改成1串'
print c.reshape(-1)
输出为:
改成2行3列:
[[1 2 3]
[4 5 6]]
改成3行2列:
[[1 2]
[3 4]
[5 6]]
我也不知道几行,反正是1列:
[[1]
[2]
[3]
[4]
[5]
[6]]
我也不知道几列,反正是1行:
[[1 2 3 4 5 6]]
不分行列,改成1串
[1 2 3 4 5 6]
1
from PIL import Image
from numpy import array
from numpy import random,exp
from math import pi as pai
im = array(Image.open('d:/1.jpg'))
print im.shape, im.dtype
im = array(Image.open('d:/1.jpg').convert('L'),'f') #此情况不报错, 但之前用 im = Image.open('d:/1.jpg').convert('L') 会出错,尚不清楚原因......应使用convert("L")
2
from PIL import Image
import matplotlib.pyplot as plt
img=Image.open('d:/dog.png')
plt.figure("dog")
plt.imshow(img)
plt.show()