Does np.empty_like have a parameter error?

When I use the empty_likenumpy function , I got 1 error and could not explain it myself.

Here is the code:

In [38]: aa=np.array([1,2])
In [39]: b=np.empty_like(aa)    #it is ok
In [40]: b=np.empty_like(a=aa)   #it is wrong
TypeError
Traceback (most recent call last)
<ipython-input-40-9b39ff78d8bb> in <module>()
----> 1 b=np.empty_like(a=aa)   #it is wrong
TypeError: Required argument 'prototype' (pos 1) not found

I looked at the documentation that says

empty_like(a, dtype=None, order='K', subok=True)

Returns a new array with the same shape and type as the given array.

...

What is the reason? A function has a formal parameter with a name a, but I cannot use it to call a function. Of course, this is normal for another * _like function with a.

In [42]: b=np.zeros_like(a=aa)   #it is ok

In [43]: b=np.ones_like(a=aa)   #it is ok

Does anyone know the reason? Or is it a mistake?

+4
source share
1 answer

It seems that this is an error in the attribute __doc__, forcing to help show the incorrect signature of the function:

>>>np.empty_like.__doc__
"empty_like(a, dtype=None, order='K', subok=True)\n\n

etc. After the error, however,

np.empty_like(prototype=aa)

. , a, . , -, .

+2

Source: https://habr.com/ru/post/1690604/


All Articles