Mastodon Feed: Post

Mastodon Feed

Reblogged by isagalaev ("Ivan Sagalaev :flag_wbw:"):

thatgeoguy@coales.co ("Jeremy 🇨🇦") wrote:

Is this just... evil? https://numpy.org/doc/stable/reference/generated/numpy.reshape.html

Specifically the part that says: " This will be a new view object if possible; otherwise, it will be a copy. Note there is no guarantee of the memory layout (C- or Fortran- contiguous) of the returned array."

Why in the hell would you return a view in some cases but a copy in others? That means mutability semantics aren't a big deal if it copies, but a big no-no if you get a view "for efficiency."

I can see this kind of semantic easily becoming a footgun embedded in a script somewhere. This is hardly something you'd think twice about!

#numpy #Python