question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cross-kind casting in asarray()

See original GitHub issue

Should asarray() allow arbitrary casting between dtypes if you call asarray(x, dtype=dtype)? It isn’t really clear in the spec if, e.g., asarray(x, dtype=bool) should be required to work if x is an integer or float array, or asarray(x, dtype=float64) if x is integer, and so on. My feeling is that it definitely should work if dtype is a promotable type from x.dtype, but I don’t know if casts that aren’t required to promote should also be required to work.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
asmeurercommented, Sep 20, 2021

Oh yeah you are right about the _like functions (those always confuse me tbh because they seem rather pointless, but that’s neither here nor there).

0reactions
kgrytecommented, Sep 18, 2021

@asmeurer I am not seeing how the *_like functions are affected by cross-kind casting, as discussed in this issue. Maybe I am missing something, but the *_like functions don’t perform casting; the data of the input array is not touched.

Read more comments on GitHub >

github_iconTop Results From Across the Web

numpy.asarray — NumPy v1.24 Manual
Reference object to allow the creation of arrays which are not NumPy arrays. If an array-like passed in as like supports the __array_function__...
Read more >
numpy.asarray() - JAX documentation - Read the Docs
LAX-backend implementation of numpy.asarray() . This function will create arrays on JAX's default device. For control of the device placement of data, see...
Read more >
Test suite for the PyData Array APIs standard - GitHub
Testing asarray() works with scalars (and nested sequences of scalars) is fundamental to testing that it works with arrays, as said arrays can...
Read more >
numpy.asarray() in Python - GeeksforGeeks
numpy.asarray() function is used when we want to convert input to an array. Input can be lists, lists of tuples, tuples, tuples of...
Read more >
What is the difference between np.array() and np.asarray()?
asarray() with the example: np.array(): Convert input data (list, tuple, array, or other sequence type) to an ndarray and copies the input data ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found