Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@(at) operator at Python, how to use it? [duplicate]

I'm trying to run a python code. This code have an '@' ( at) operator. I never saw it before, and Google returns no hits.

init = model.potentials[key].init_weights(model)
if init.ndim==2:
    U, S, Vt = np.linalg.svd(init, False)
    init = U@Vt

It says the following error:

init = U@Vt
        ^
SyntaxError: invalid syntax

I'm using Python 2.7 to compile it. Do anyone know about this operator ?

like image 884
bratao Avatar asked Jun 23 '16 04:06

bratao


1 Answers

The @ operator was proposed in PEP 465 and adopted into Python 3.5. You can't use it because you are using an older branch of Python. It is used to multiply matrixes (usually, but you can actually make @ do anything). You can use numpy.dot() instead if you are working with NumPy arrays, like this:

init = model.potentials[key].init_weights(model)
if init.ndim==2:
    U, S, Vt = np.linalg.svd(init, False)
    init = np.dot(U, Vt)
like image 123
Dietrich Epp Avatar answered Oct 20 '22 11:10

Dietrich Epp