Python Numpy教程(图片问题搁置)

Python

Python是一种高级动态类型的多范式编程语言。

Python中经典快递排序算法的实现:

Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def quicksort(arr):
...     if len(arr)<=1:
...             return arr
...     pivot=arr[len(arr)//2]
...     left=[x for x in arr if x<pivot]
...     middle=[x for x in arr if x==pivot]
...     right=[x for x in arr if x>pivot]
...     return quicksort(left)+middle+quicksort(right)
...
>>> print(quicksort([3,6,8,10,1,2,1]))
[1, 1, 2, 3, 6, 8, 10]
>>>

基本数据类型

Numbers(数字类型):

>>> x=3
>>> print(type(x))
<class 'int'>
>>> print(x)
3
>>> print(x+1)
4
>>> print(x-1)
2
>>> print(x*2)
6
>>> print(x**2)
9
>>> x+=1
>>> print(x)
4
>>> x*=2
>>> print(x)
8
>>> y=2.5
>>> print(type(y))
<class 'float'>
>>> print(y,y+1,y*2,y**2)
2.5 3.5 5.0 6.25
>>>

Booleans(布尔类型):

>>> t=True
>>> f=False
>>> print(type(t))
<class 'bool'>
>>> print(t and f)
False
>>> print(t or f)
True
>>> print(not t)
False
>>> print(t!=f)
True
>>>

Strings(字符串类型):

>>> hello='hello'
>>> world='world'
>>> print(hello)
hello
>>> print(len(hello))
5
>>> hw=hello+' '+world
>>> print(hw)
hello world
>>> hw12='%s %s %d' % (hello, world, 12)
>>> print(hw12)
hello world 12
>>>
>>> s="hello"
>>> print(s.capitalize())
Hello
>>> print(s.upper())
HELLO
>>> print(s.rjust(7))
  hello
>>> print(s.center(7))
 hello
>>> print(s.replace('1','(ell)'))
hello
>>> print('  world '.strip())
world
>>>

容器(Containers)

Python包含几种内置的容器类型:列表、字典、集合和元组。

列表(Lists):可以动态的调整大小并且可以包含不同类型的元素。

>>> xs=[3,1,2]
>>> print(xs,xs[2])
[3, 1, 2] 2
>>> print(xs[-1])
2
>>> xs[2]='foo'
>>> print(xs)
[3, 1, 'foo']
>>> xs.append('bar')
>>> print(xs)
[3, 1, 'foo', 'bar']
>>> x=xs.pop()
>>> print(x,xs)
bar [3, 1, 'foo']
>>>

切片(Slicing)提供访问子列表的简明语法。

>>> nums=list(range(5))
>>> print(nums)
[0, 1, 2, 3, 4]
>>> print(nums[2:4])
[2, 3]
>>> print(nums[2:])
[2, 3, 4]
>>> print(nums[:2])
[0, 1]
>>> print(nums[:])
[0, 1, 2, 3, 4]
>>> print(nums[:-1])
[0, 1, 2, 3]
>>> nums[2:4]=[8,9]
>>> print(nums)
[0, 1, 8, 9, 4]
>>>

循环(Loops):循环遍历列表的元素。

>>> animals=['cat','dog','monkey']
>>> for animal in animals:
...     print(animal)
...
cat
dog
monkey
>>> animals=['cat','dog','monkey']
>>> for idx,animal in enumerate(animals):
...     print('#%d: %s' %(idx+1,animal))
...
#1: cat
#2: dog
#3: monkey
>>>

列表推导体(List comprehensions):编程时,将一种数据转换为另一个数据。

>>> nums=[0,1,2,3,4]
>>> squares=[]
>>> for x in nums:
...     squares.append(x**2)
...
>>> print(squares)
[0, 1, 4, 9, 16]
>>> nums=[0,1,2,3,4]
>>> squares=[x**2 for x in nums]
>>> print(squares)
[0, 1, 4, 9, 16]
>>> nums=[0,1,2,3,4]
>>> even_squares=[x**2for x in nums if x%2==0]
>>> print(even_squares)
[0, 4, 16]
>>>

字典:字典存储(键、值)对。

>>> d={'cat':'cute','dog':'furry'}
>>> print(d['cat'])
cute
>>> print('cat' in d)
True
>>> d['fish']='wet'
>>> print(d['fish'])
wet
>>> print(d.get('monkey','N/A'))
N/A
>>> print(d.get('fish','N/A'))
wet
>>> del d['fish']
>>> print(d.get('fish','N/A'))
N/A
>>>

循环(Loops):

>>> d={'penson':2,'cat':4,'spider':8}
>>> for animal,legs in d.items():
...     print('A %s has %d legs' % (animal,legs))
...
A penson has 2 legs
A cat has 4 legs
A spider has 8 legs
>>>

>>> d={'penson':2,'cat':4,'spider':8}
>>> for animal,legs in d.items():
...     print('A %s has %d legs' % (animal,legs))
...
A penson has 2 legs
A cat has 4 legs
A spider has 8 legs
>>>

字典推导式(Dictionary comprehensions):

>>> nums=[0,1,2,3,4]
>>> even_num_to_square={x:x**2 for x in nums if x%2==0}
>>> print(even_num_to_square)
{0: 0, 2: 4, 4: 16}
>>>

集合(Sets)

集合是不同元素的无序集合。

>>> animals={'cat','dog'}
>>> print('cat' in animals)
True
>>> print('fish' in animals)
False
>>> animals.add('fish')
>>> print('fish' in animals)
True
>>> print(len(animals))
3
>>> animals.add('cat')
>>> print(len(animals))
3
>>> animals.remove('cat')
>>> print(len(animals))
2
>>>

循环(Loops):

>>> animals={'cat','dog','fish'}
>>> for idx, animal in enumerate(animals):
...     print('#%d: %s' % (idx+1, animal))
...
#1: cat
#2: fish
#3: dog
>>>

集合推导式(Set comprehensions):

>>> from math import sqrt
>>> nums={int(sqrt(x)) for x in range(30)}
>>> print(nums)
{0, 1, 2, 3, 4, 5}
>>>

元组(Tuples):元组是不可变的有序值列表。无级可以用作字典中的键和集合的元素,而列表则不能。

>>> d={(x,x+1):x for x in range(10)}
>>> t=(5,6)
>>> print(type(t))
<class 'tuple'>
>>> print(d[t])
5
>>> print(d[(1,2)])
1
>>>

函数(Functions)

Python函数使用def关键字定义。

>>> def sign(x):
...     if x>0:
...             return 'positive'
...     elif x<0:
...             return 'negative'
...     else:
...             return 'zero'
...
>>> for x in [-1,0,1]:
...     print(sign(x))
...
negative
zero
positive
>>>

>>> def hello(name,loud=False):
...     if loud:
...             print('HELLO, %s!' % name.upper())
...     else:
...             print('HELLO, %s' % name)
...
>>> hello('Bob')
HELLO, Bob
>>> hello('Fred', loud=True)
HELLO, FRED!
>>>

类(Classes)

>>> class Greeter(object):
...     def __init__(self,name):
...             self.name=name
...
>>> class Greeter(object):
...     def __init__(self,name):
...             self.name=name
...     def greet(self,loud=False):
...             if loud:
...                     print('HELLO, %s!' % self.name.upper())
...             else:
...                     print('Hello, %s' % self.name)
...
>>> g=Greeter('Fred')
>>> g.greet()
Hello, Fred
>>> g.greet(loud=True)
HELLO, FRED!
>>>

Numpy

数组(Arrays)

numpy数组是一个值网格,所有类型都相同,并由非负整数元组索引。

>>> import numpy as np
>>> a=np.array([1,2,3])
>>> print(type(a))
<class 'numpy.ndarray'>
>>> print(a.shape)
(3,)
>>> print(a[0],a[1],a[2])
1 2 3
>>> a[0]=5
>>> print(a)
[5 2 3]
>>> 
>>> b=np.array([[1,2,3],[4,5,6]])
>>> print(b.shape)
(2, 3)
>>> print(b[0,0],b[0,1],b[1,0])
1 2 4
>>>

>>> import numpy as np
>>> a=np.zeros((2,2))
>>> print(a)
[[0. 0.]
 [0. 0.]]
>>> b=np.ones((1,2))
>>> print(b)
[[1. 1.]]
>>> c=np.full((2,2),7)
>>> print(c)
[[7 7]
 [7 7]]
>>> d=np.eye(2)
>>> print(d)
[[1. 0.]
 [0. 1.]]
>>> e=np.random.random((2,2))
>>> print(e)
[[0.58708999 0.38833429]
 [0.7835636  0.98677119]]
>>>

数组索引

切片:

>>> import numpy as np
>>> a=np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]])
>>> b=a[:2,1:3]
>>> print(a)
[[ 1  2  3  4]
 [ 5  6  7  8]
 [ 9 10 11 12]]
>>> print(b)
[[2 3]
 [6 7]]
>>> print(a[0,1])
2
>>> b[0,0]=77
>>> print(a[0,1])
77
>>> print(a)
[[ 1 77  3  4]
 [ 5  6  7  8]
 [ 9 10 11 12]]
>>> print(b)
[[77  3]
 [ 6  7]]
>>>

>>> import numpy as np
>>> a=np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]])
>>> row_r1=a[1,:]
>>> row_r2=a[1:2,:]
>>> print(row_r1,row_r1.shape)
[5 6 7 8] (4,)
>>> print(row_r2,row_r2.shape)
[[5 6 7 8]] (1, 4)
>>> col_r1=a[:,1]
>>> col_r2=a[:,1:2]
>>> print(col_r1,col_r1.shape)
[ 2  6 10] (3,)
>>> print(col_r2,col_r2.shape)
[[ 2]
 [ 6]
 [10]] (3, 1)
>>> print(row_r1)
[5 6 7 8]
>>> print(row_r2)
[[5 6 7 8]]
>>> print(col_r1)
[ 2  6 10]
>>> print(col_r2)
[[ 2]
 [ 6]
 [10]]
>>>

整数数组索引:使用切片索引到numpy数组时,生成的数组视图将始终是原始数组的子数组。 相反,整数数组索引允许你使用另一个数组中的数据构造任意数组。

>>> import numpy as np
>>> a=np.array([[1,2],[3,4],[5,6]])
>>> print(a[[0,1,2],[0,1,0]])
[1 4 5]
>>> print(np.array([a[0,0],a[1,1],a[2,0]]))
[1 4 5]
>>> print(a[[0,0],[1,1]])
[2 2]
>>> print(np.array([a[0,1],a[0,1]]))
[2 2]
>>>

>>> import numpy as np
>>> a=np.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12]])
>>> print(a)
[[ 1  2  3]
 [ 4  5  6]
 [ 7  8  9]
 [10 11 12]]
>>> b=np.array([0,2,0,1])
>>> print(b)
[0 2 0 1]
>>> print(a[np.arange(4),b])
[ 1  6  7 11]
>>> a[np.arange(4),b]+=10
>>> print(a)
[[11  2  3]
 [ 4  5 16]
 [17  8  9]
 [10 21 12]]
>>>

布尔数组索引:

>>> import numpy as np
>>> a=np.array([[1,2],[3,4],[5,6]])
>>> bool_idx=(a>2)
>>> print(bool_idx)
[[False False]
 [ True  True]
 [ True  True]]
>>> print(a[bool_idx])
[3 4 5 6]
>>> print(a[a>2])
[3 4 5 6]
>>>

数据类型

每个numpy数组都是相同类型元素的网格。Numpy提供了一组可用于构造数组的大量数值数据类型。Numpy在创建数组时尝试猜测数据类型,但构造数组的函数通常还包含一个可选参数来显式指定数据类型。

>>> import numpy as np
>>> x=np.array([1,2])
>>> print(x.dtype)
int32
>>> x=np.array([1.0,2.0])
>>> print(x.dtype)
float64
>>> x=np.array([1,2],dtype=np.int64)
>>> print(x.dtype)
int64
>>>

数组中的数学

>>> import numpy as np
>>> x=np.array([[1,2],[3,4]],dtype=np.float64)
>>> y=np.array([[5,6],[7,8]],dtype=np.float64)
>>> print(x)
[[1. 2.]
 [3. 4.]]
>>> print(y)
[[5. 6.]
 [7. 8.]]
>>> print(x+y)
[[ 6.  8.]
 [10. 12.]]
>>> print(np.add(x,y))
[[ 6.  8.]
 [10. 12.]]
>>> print(x-y)
[[-4. -4.]
 [-4. -4.]]
>>> print(np.subtract(x,y))
[[-4. -4.]
 [-4. -4.]]
>>> print(x*y)
[[ 5. 12.]
 [21. 32.]]
>>> print(np.multiply(x,y))
[[ 5. 12.]
 [21. 32.]]
>>> print(x/y)
[[0.2        0.33333333]
 [0.42857143 0.5       ]]
>>> print(np.divide(x,y))
[[0.2        0.33333333]
 [0.42857143 0.5       ]]
>>> print(np.sqrt(x))
[[1.         1.41421356]
 [1.73205081 2.        ]]
>>>

与MATLAB不同,*是元素乘法,而不是矩阵乘法。 我们使用dot函数来计算向量的内积,将向量乘以矩阵,并乘以矩阵。 dot既可以作为numpy模块中的函数,也可以作为数组对象。

>>> import numpy as np
>>> x=np.array([[1,2],[3,4]])
>>> y=np.array([[5,6],[7,8]])
>>> v=np.array([9,10])
>>> w=np.array([11,12])
>>> print(v.dot(w))
219
>>> print(np.dot(v,w))
219
>>> print(x.dot(v))
[29 67]
>>> print(np.dot(x,v))
[29 67]
>>> print(x.dot(y))
[[19 22]
 [43 50]]
>>> print(np.dot(x,y))
[[19 22]
 [43 50]]
>>>

>>> import numpy as np
>>> x=np.array([[1,2],[3,4]])
>>> print(np.sum(x))
10
>>> print(np.sum(x,axis=0))
[4 6]
>>> print(np.sum(x,axis=1))
[3 7]
>>>

要转置一个矩阵,只需使用一个数组对象的T属性:

>>> import numpy as np
>>> x=np.array([[1,2],[3,4]])
>>> print(x)
[[1 2]
 [3 4]]
>>> print(x.T)
[[1 3]
 [2 4]]
>>> v=np.array([1,2,3])
>>> print(v)
[1 2 3]
>>> print(v.T)
[1 2 3]
>>>

广播(Broadcasting)

广播是一种强大的机制,它允许numpy在执行算术运算时使用不同形状的数组。通常,我们有一个较小的数组和一个较大的数组,我们希望多次使用较小的数组来对较大的数组执行一些操作。

>>> import numpy as np
>>> x=np.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12]])
>>> v=np.array([1,0,1])
>>> y=np.empty_like(x)
>>> print(x)
[[ 1  2  3]
 [ 4  5  6]
 [ 7  8  9]
 [10 11 12]]
>>> print(v)
[1 0 1]
>>> print(y)
[[          0           0 -1990463632]
 [        401          24   175243264]
 [-1988423248         401           1]
 [ 1963317760  1852795246         196]]
>>> for i in range(4):
...     y[i,:]=x[i,:]+v
...
>>> print(y)
[[ 2  2  4]
 [ 5  5  7]
 [ 8  8 10]
 [11 11 13]]
>>>

>>> import numpy as np
>>> x=np.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12]])
>>> v=np.array([1,0,1])
>>> vv=np.tile(v,(4,1))
>>> print(x)
[[ 1  2  3]
 [ 4  5  6]
 [ 7  8  9]
 [10 11 12]]
>>> print(v)
[1 0 1]
>>> print(vv)
[[1 0 1]
 [1 0 1]
 [1 0 1]
 [1 0 1]]
>>> y=x+vv
>>> print(y)
[[ 2  2  4]
 [ 5  5  7]
 [ 8  8 10]
 [11 11 13]]
>>>

>>> import numpy as np
>>> x=np.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12]])
>>> v=np.array([1,0,1])
>>> y=x+v
>>> print(y)
[[ 2  2  4]
 [ 5  5  7]
 [ 8  8 10]
 [11 11 13]]
>>>

>>> import numpy as np
>>> v=np.array([1,2,3])
>>> w=np.array([4,5])
>>> print(np.reshape(v,(3,1))*w)
[[ 4  5]
 [ 8 10]
 [12 15]]
>>> x=np.array([[1,2,3],[4,5,6]])
>>> print(x+v)
[[2 4 6]
 [5 7 9]]
>>> print(x.T)
[[1 4]
 [2 5]
 [3 6]]
>>> print((x.T+w))
[[ 5  9]
 [ 6 10]
 [ 7 11]]
>>> print((x.T+w).T)
[[ 5  6  7]
 [ 9 10 11]]
>>> print(np.reshape(w,(2,1)))
[[4]
 [5]]
>>> print(x+np.reshape(w,(2,1)))
[[ 5  6  7]
 [ 9 10 11]]
>>> print(x*2)
[[ 2  4  6]
 [ 8 10 12]]
>>>

SciPy

Numpy提供了一个高性能的多维数组和基本工具来计算和操作这些数组。 而SciPy以此为基础,提供了大量在numpy数组上运行的函数,可用于不同类型的科学和工程应用程序。

图像操作

 SciPy提供了一些处理图像的基本函数。

PS C:\Users\a-xiaobodou> pip install scipy
Requirement already satisfied: scipy in c:\users\a-xiaobodou\appdata\local\programs\python\python310\lib\site-packages (1.8.0)
Requirement already satisfied: numpy<1.25.0,>=1.17.3 in c:\users\a-xiaobodou\appdata\local\programs\python\python310\lib\site-packages (from scipy) (1.22.3)
PS C:\Users\a-xiaobodou>

>>> from scipy.misc import imread,imsave, imresize
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'imread' from 'scipy.misc' (C:\Users\a-xiaobodou\AppData\Local\Programs\Python\Python310\lib\site-packages\scipy\misc\__init__.py)
>>>

这个问题不得不暂停了,只能等待。

MATLAB文件

函数 scipy.io.loadmat 和 scipy.io.savemat 允许你读取和写入MATLAB文件。

点之间的距离

>>> import numpy as np
>>> from scipy.spatial.distance import pdist,squareform
>>> x=np.array([[0,1],[1,0],[2,0]])
>>> print(x)
[[0 1]
 [1 0]
 [2 0]]
>>> d=squareform(pdist(x,'euclidean'))
>>> print(d)
[[0.         1.41421356 2.23606798]
 [1.41421356 0.         1.        ]
 [2.23606798 1.         0.        ]]
>>>

Matplotlib

Matplotlib是一个绘图库。 matplotlib.pyplot 模块,提供了类似于MATLAB的绘图系统。

绘制

matplotlib中最重要的功能是plot,它允许你绘制2D数据的图像。

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> x=np.arange(0,3*np.pi,0.1)
>>> y=np.sin(x)
>>> plt.plot(x,y)
[<matplotlib.lines.Line2D object at 0x0000019194E67DC0>]
>>> plt.show()
>>>

 

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> x=np.arange(0,3*np.pi,0.1)
>>> print(x)
[0.  0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.  1.1 1.2 1.3 1.4 1.5 1.6 1.7
 1.8 1.9 2.  2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.  3.1 3.2 3.3 3.4 3.5
 3.6 3.7 3.8 3.9 4.  4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5.  5.1 5.2 5.3
 5.4 5.5 5.6 5.7 5.8 5.9 6.  6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.  7.1
 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.  8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9
 9.  9.1 9.2 9.3 9.4]
>>> y_sin=np.sin(x)
>>> print(y_sin)
[ 0.          0.09983342  0.19866933  0.29552021  0.38941834  0.47942554
  0.56464247  0.64421769  0.71735609  0.78332691  0.84147098  0.89120736
  0.93203909  0.96355819  0.98544973  0.99749499  0.9995736   0.99166481
  0.97384763  0.94630009  0.90929743  0.86320937  0.8084964   0.74570521
  0.67546318  0.59847214  0.51550137  0.42737988  0.33498815  0.23924933
  0.14112001  0.04158066 -0.05837414 -0.15774569 -0.2555411  -0.35078323
 -0.44252044 -0.52983614 -0.61185789 -0.68776616 -0.7568025  -0.81827711
 -0.87157577 -0.91616594 -0.95160207 -0.97753012 -0.993691   -0.99992326
 -0.99616461 -0.98245261 -0.95892427 -0.92581468 -0.88345466 -0.83226744
 -0.77276449 -0.70554033 -0.63126664 -0.55068554 -0.46460218 -0.37387666
 -0.2794155  -0.1821625  -0.0830894   0.0168139   0.1165492   0.21511999
  0.31154136  0.40484992  0.49411335  0.57843976  0.6569866   0.72896904
  0.79366786  0.85043662  0.8987081   0.93799998  0.96791967  0.98816823
  0.99854335  0.99894134  0.98935825  0.96988981  0.94073056  0.90217183
  0.85459891  0.79848711  0.7343971   0.66296923  0.58491719  0.50102086
  0.41211849  0.31909836  0.22288991  0.12445442  0.02477543]
>>> y_cos=np.cos(x)
>>> print(y_cos)
[ 1.          0.99500417  0.98006658  0.95533649  0.92106099  0.87758256
  0.82533561  0.76484219  0.69670671  0.62160997  0.54030231  0.45359612
  0.36235775  0.26749883  0.16996714  0.0707372  -0.02919952 -0.12884449
 -0.22720209 -0.32328957 -0.41614684 -0.5048461  -0.58850112 -0.66627602
 -0.73739372 -0.80114362 -0.85688875 -0.90407214 -0.94222234 -0.97095817
 -0.9899925  -0.99913515 -0.99829478 -0.98747977 -0.96679819 -0.93645669
 -0.89675842 -0.84810003 -0.79096771 -0.7259323  -0.65364362 -0.57482395
 -0.49026082 -0.40079917 -0.30733287 -0.2107958  -0.11215253 -0.01238866
  0.08749898  0.18651237  0.28366219  0.37797774  0.46851667  0.55437434
  0.63469288  0.70866977  0.77556588  0.83471278  0.88551952  0.92747843
  0.96017029  0.98326844  0.9965421   0.99985864  0.99318492  0.97658763
  0.95023259  0.91438315  0.86939749  0.8157251   0.75390225  0.68454667
  0.60835131  0.52607752  0.43854733  0.34663532  0.25125984  0.15337386
  0.05395542 -0.04600213 -0.14550003 -0.24354415 -0.33915486 -0.43137684
 -0.51928865 -0.6020119  -0.67872005 -0.74864665 -0.81109301 -0.86543521
 -0.91113026 -0.9477216  -0.97484362 -0.99222533 -0.99969304]
>>> plt.plot(x,y_sin)
[<matplotlib.lines.Line2D object at 0x0000019194CED540>]
>>> plt.plot(x,y_cos)
[<matplotlib.lines.Line2D object at 0x0000019194CED870>]
>>> plt.xlabel('x axis label')
Text(0.5, 0, 'x axis label')
>>> plt.ylabel('y axis label')
Text(0, 0.5, 'y axis label')
>>> plt.title('Sine and Cosine')
Text(0.5, 1.0, 'Sine and Cosine')
>>> plt.legend(['Sine','Cosine'])
<matplotlib.legend.Legend object at 0x0000019194E67D60>
>>> plt.show()
>>>

 

子图

使用subplot函数在同一个图中绘制不同的东西。

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> x=np.arange(0,3*np.pi,0.1)
>>> y_sin=np.sin(x)
>>> y_cos=np.cos(x)
>>> plt.subplot(2,1,1)
<AxesSubplot:>
>>> plt.plot(x,y_sin)
[<matplotlib.lines.Line2D object at 0x0000019194D6F3D0>]
>>> plt.title('Sine')
Text(0.5, 1.0, 'Sine')
>>> plt.subplot(2,1,2)
<AxesSubplot:>
>>> plt.plot(x,y_cos)
[<matplotlib.lines.Line2D object at 0x0000019192414E80>]
>>> plt.title('Cosine')
Text(0.5, 1.0, 'Cosine')
>>> plt.show()
>>>

 

图片

使用 imshow 函数来显示一张图片。

>>> import numpy as np
>>> from scipy.misc import imread,imresize
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'imread' from 'scipy.misc' (C:\Users\a-xiaobodou\AppData\Local\Programs\Python\Python310\lib\site-packages\scipy\misc\__init__.py)
>>>

这个问题不得不暂停了,只能等待。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值