深度学习入门ch2a numpy型感知器1(jupyter note)

深度学习入门ch2a numpy型感知器1(note)

In [59]:

import numpy as np
x=np.array([1.0, 3.0,5.0])
print(x)
print(type(x))

Output:

[1. 3. 5.]
<class 'numpy.ndarray'>

In [60]:

y=np.array([10.0,20.0,30.0])
z=x+y
print(z)
print(y/x)
print(x*y)
print(x/2.0)

Output:

[11. 23. 35.]
[10.          6.66666667  6.        ]
[ 10.  60. 150.]
[0.5 1.5 2.5]

In [61]:

a=np.array([[1.2,2.4],[3.6,4.8]]) # double []
print(a)
print(a.shape)
print(a.dtype)

Output:

[[1.2 2.4]
 [3.6 4.8]]
(2, 2)
float64

In [62]:

b=np.array([[5,10],[7,11]])
print(a+b)
print(a*b)

Output:

[[ 6.2 12.4]
 [10.6 15.8]]
[[ 6.  24. ]
 [25.2 52.8]]

In [63]:

a2 = np.array([[1,2],[3,4]])
b2 = np.array([10,20])
print(a2*b2)
print(a2[0])
print(a2[1][1])

Output:

[[10 40]
 [30 80]]
[1 2]
4

In [64]:

for row in a2:
    print(row)

Output:

[1 2]
[3 4]

In [65]:

print(y.flatten())
print(y[1,2])  # it is wrong using index directly

Output:

[10. 20. 30.]
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-65-aaf42b68dd20> in <module>()
      1 print(y.flatten())
----> 2 print(y[1,2])  # it is wrong using index directly

IndexError: too many indices for array

In [70]:

print(y[np.array([0,2])]) #using [] and np ndarray

Output:

[10. 30.]

In [71]:

print(y)
y2 = y > 15
print(y>15)
print(type(y2))

Output:

[10. 20. 30.]
[False  True  True]
<class 'numpy.ndarray'>

In [72]:

print(y[y>15])  # if true , fetch out,取出true对应的元素

Output:

[20. 30.]

In [66]:

import matplotlib.pyplot as plt
%pylab inline
x=np.arange(0,6,0.1)  # step is 0.1
y1=np.sin(x)
y2=np.cos(x)
plt.plot(x,y1,label="sin")
plt.plot(x,y2,linestyle="--",label="cos")
plt.xlabel("x")
plt.ylabel("y")
plt.title('sin & cos')
plt.legend()
plt.show()

Output:

Populating the interactive namespace from numpy and matplotlib

在这里插入图片描述

In [69]:

import os
from matplotlib.image import imread
img = imread('C:\\Users\\Administrator\\0009.jpg')
plt.imshow(img)

Output:

Out[69]:

<matplotlib.image.AxesImage at 0xc9de908>

| 在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值