Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

what does mean + + operator in python numpy

I’ve met following statement in python numpy library

Z = inputs @ self.weights[1:].T + + self.weights[0]

I don’t understand exactly what does it mean in this line of code

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’ve made researchtations and did not found proper explanation

>Solution :

There is no + + operator in Python. This is two separate operators, the unary positive operator and the binary sum operator. Observe:

>>> import dis
>>> dis.dis("x + + y")
  0           0 RESUME                   0

  1           2 LOAD_NAME                0 (x)
              4 LOAD_NAME                1 (y)
              6 CALL_INTRINSIC_1         5 (INTRINSIC_UNARY_POSITIVE)
              8 BINARY_OP                0 (+)
             12 RETURN_VALUE

Similar to the unary negative operator, -. e.g:

x = 10
y = -x
print(y) # -10

I suspect this is just a typo. Cases where unary + actually matters are extremely rare, and this doesn’t look like one of them. Particularly, unary + is not an absolute value operator – if the input is negative, the output will be negative too.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading