Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to multiply Keras tensor by scalar?

Tags:

keras

tensor

if I have tensors, v, w, I know you can multiply them together with

a = Multiply()([v, w])

But what if I want to multiply v or w by a scalar?

like image 579
user5739619 Avatar asked Feb 22 '18 23:02

user5739619


2 Answers

You can use a Lambda layer for any other scalar manipulations

Scalar Multiplication:

res5 = Lambda(lambda x: x * 3)(res4)

Scalar Addition:

res5 = Lambda(lambda x: x + 4)(res4)
like image 184
bachr Avatar answered Oct 13 '22 01:10

bachr


If you are using tensorflow as your backend, the * operator is supported (see this answer).

a = v * 0.10

like image 35
warpri81 Avatar answered Oct 13 '22 03:10

warpri81