Skip to Content
深度学习入门 : 基于Python的理论与实现
book

深度学习入门 : 基于Python的理论与实现

by 斋藤康毅
July 2018
Intermediate to advanced
310 pages
8h 21m
Chinese
Posts & Telecom Press
Content preview from 深度学习入门 : 基于Python的理论与实现
3章 神经网络
44
>>> y
array([False, True, True], dtype=bool)
NumPy
数组进行不等号运算后,数组的各个元素都会进行不等号运算,
生成一个布尔型数组。这里,数组
x
中大于0 的元素被转换为
True
,小于等
0 的元素被转换为
False
,从而生成一个新的数组
y
数组
y
是一个布尔型数组,但是我们想要的阶跃函数是会输出
int
型的0
1 的函数。因此,需要把数组
y
的元素类型从布尔型转换为
int
型。
>>> y = y.astype(np.int)
>>> y
array([0, 1, 1])
如上所示,可以用
astype()
方法转换
NumPy
数组的类型。
astype()
法通过参数指定期望的类型,这个例子中是
np.int
型。
Python
中将布尔型
转换为
int
型后,
True
会转换为1
False
会转换为0。以上就是阶跃函数的
实现中所用到的
NumPy
的“技巧”。
3.2.3
 阶跃函数的图形
下面我们就用图来表示上面定义的阶跃函数,为此需要使用
matplotlib
库。
import numpy as np
import matplotlib.pylab as plt
def step_function(x):
return np.array(x > 0, dtype=np.int)
x = np.arange(-5.0, 5.0, 0.1)
y = step_function(x)
plt.plot(x, y)
plt.ylim(-0.1, 1.1) #
指定
y
轴的范围 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

ルールズ・オブ・プログラミング ―より良いコードを書くための21のルール

ルールズ・オブ・プログラミング ―より良いコードを書くための21のルール

Chris Zimmerman, 久富木 隆一

Publisher Resources

ISBN: 9787115485588