Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this simple numpy multiply operation raise an "invalid number of arguments" error? [duplicate]

Tags:

python

numpy

This works

numpy.multiply(13, 3)

This doesn't

numpy.multiply(x1=13, x2=3)

It raises an invalid number of arguments exception. Can someone explain why please. I tried to follow the documentation but got a bit lost with the /, and * characters which are included in the argument list. If you could explain the meaning of these too it would be appreciated.

like image 355
Jinglesting Avatar asked Feb 27 '18 13:02

Jinglesting


People also ask

Can we use the NumPy multiply function in two NumPy arrays?

In simple words, No, we can’t find products or use the numpy multiply function in two numpy arrays that have different shapes. If the shape of two numpy arrays is different, then we will get a value error. The value error will say something like, for example.

How to do arithmetic operations on NumPy arrays?

All the arithmetic operations work in a similar way. You can also multiply or divide the arrays. The operations are performed element-wise. Similar to programming languages like C# and Java, you can also use operators like +=, * = on your Numpy arrays. For example, we have the array:

What is logical_and and logical_or in NumPy?

Each of the values in the resulting array represents the lowest value for that particular row. Numpy provides logic functions like logical_and, logical_or etc., in a similar pattern to perform logical operations. For example: In addition to arithmetic operators, Numpy also provides functions to perform arithmetic operations.

How do you use a conditional expression in NumPy?

Using Numpy with Conditional Expressions You can use conditionals to find the values that match your criteria. Since array1 is an array, the result of a conditional operation is also an array. When we perform a conditional check, the output is an array of booleans.


1 Answers

https://docs.scipy.org/doc/numpy/reference/generated/numpy.multiply.html

The / and * delimit positional-only and keyword-only arguments, respectively. Any arguments listed before the / can only be given as positional arguments, with no keyword (i.e. no x1, x2). Arguments listed after the * can only be given with a keyword.

Keyword-Only Arguments

Positional-Only Arguments

like image 68
Mark Whitfield Avatar answered Sep 21 '22 02:09

Mark Whitfield