pytorch / pytorch/pytorch

api shows unexpected difference for flatten(): numpy vs. pytorch

Open
#177,957 1 comment 0 reactions 0 assignees View on GitHub
bot-triaged enhancement module: docs triaged
Dominant language
Python
Stars
103k
Forks
29.5k
PR merge metrics
PR metrics pending

Description

### 🐛 Describe the bug

# simple code sample
```py
import numpy as np
import torch as tt
v = np.ones((2,2))
t = tt.ones((2,2))
v.flatten()[:] = np.zeros(4)
t.flatten()[:] = tt.zeros(4)
v, t
(array([[1., 1.],
[1., 1.]]),
tensor([[0., 0.],
[0., 0.]]))
```
this deviation is dangerous and should be clearly mentioned in documentation,
or better changed (likely on numpy side, in my opinion)

### Versions

Python 3.13.12, Windows 10
numpy 2.3.5
torch 2.10.0+cu130

cc @svekars @sekyondaMeta @AlannaBurke

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.