How to multiply Keras tensor by scalar?

user5739619 picture user5739619 · Feb 23, 2018 · Viewed 10.6k times · Source

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?

Answer

bachr picture bachr · Nov 18, 2018

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)