[Numpy-discussion] Using scalar constructors to produce arrays
Ralf Gommers
ralf.gommers at gmail.com
Sun Apr 19 15:07:56 EDT 2020
On Sun, Apr 19, 2020 at 8:47 PM Joshua Wilson <josh.craig.wilson at gmail.com>
wrote:
> Over in the NumPy stubs there's an issue
>
> https://github.com/numpy/numpy-stubs/issues/41
>
> which points out that you can in fact do something like
>
> ```
> np.float32([1.0, 0.0, 0.0])
> ```
>
> to construct an ndarray of float32. It seems to me that though you can
> do that, it is not a best practice, and one should instead do
>
> ```
> np.array([1.0, 0.0, 0.0], dtype=np.float32)
> ```
>
> Do people agree with that assessment of what the best practice is? If
> so, it seems to make the most sense to continue banning constructs
> like `np.float32([1.0, 0.0, 0.0])` in the type stubs (as they should
> promote making easy-to-understand, scalable NumPy code).
>
+1 for banning that construct, that's really ugly
Cheers,
Ralf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20200419/cd674b3b/attachment.html>
More information about the NumPy-Discussion
mailing list