Skip to Content
ゼロから作るDeep Learning ❸ ―フレームワーク編
book

ゼロから作るDeep Learning ❸ ―フレームワーク編

by 斎藤 康毅
April 2020
Intermediate to advanced
552 pages
6h 13m
Japanese
O'Reilly Japan, Inc.
Content preview from ゼロから作るDeep Learning ❸ ―フレームワーク編

ステップ22演算子のオーバーロード(3)

前ステップでは、*+の2つの演算子に対応しました。もちろん、この他にも演算子は存在します。本ステップでは、表22-1の演算子を新たに追加します。

表22-1 本ステップで新たに追加する演算子

特殊メソッド
__neg__(self)-self
__sub__(self, other)self - other
__rsub__(self, other)other - self
__truediv__(self, other)self / other
__rtruediv__(self, other)other / self
__pow__(self, other)self ** other

表22-1の1つ目の__neg__(self)は、負数のための演算子です。この__neg__(self)は1つの項に対しての演算子です(このような演算子を「単項演算子」と言います)。そのため、その特殊メソッドの引数も1つになります。残りの演算は、引き算、割り算、累乗です。前にも述べたとおり、これらは2つの項に対して使う演算子です(a - ba / bなど)。そのため、右と左のどちらの項を対象とするかで2つの特殊メソッドに分けられます。ただし、累乗についてはx ** 3のようなケース――左項がVariableインスタンスで右項は定数(2や3などのint)の場合――のみを考えることにします。

[警告]

Pythonの演算子は、表22-1の他にもいくつか存在します。たとえば、 ...

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

ゼロから作るDeep Learning ❻ ―LLM編

ゼロから作るDeep Learning ❻ ―LLM編

斎藤 康毅

Publisher Resources

ISBN: 9784873119069Publisher Website