Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • \$\begingroup\$ It's shorter than Jelly and Ruby answers. Nice! \$\endgroup\$ Commented Sep 17, 2019 at 9:06
  • \$\begingroup\$ You can shave off 27 bytes (dropping it to 48 bytes) by removing the import entirely (just assume the caller passed you numpy.float32s so you can use their methods) and replacing both int32 uses with 'i' and the float32 usage with 'f'; the dtype parameter can be a string which gets converted to the real dtype for you, and conveniently, 'i' and 'f' are legal ways to make those dtypes, which removes the need for the function to import numpy stuff into its namespace at all. Not sure if it's Code Golf legal to remove the import but still assume numpy inputs... \$\endgroup\$ Commented Sep 17, 2019 at 19:41
  • \$\begingroup\$ Example showing it works with the import itself being unavailable to f \$\endgroup\$ Commented Sep 17, 2019 at 19:43
  • \$\begingroup\$ I thought the imports had to be included, but I’m not sure. Thanks for the tip re the dtypes! \$\endgroup\$ Commented Sep 17, 2019 at 19:44
  • \$\begingroup\$ @NickKennedy: Yeah, if the import is required, it only saves 8 bytes (two each from int32 to 'i', four from float32 to 'f'), but that's still something. If the import is strictly required, you could just change it to import numpy to assert the package exists, without using from numpy import* to extract names from it. That would get you another six bytes, down to 61 bytes total. \$\endgroup\$ Commented Sep 17, 2019 at 19:46