UserWarning: The given NumPy array is not writeable

Thanks!
What if I don’t plan on writing into to array? It will be used as input to a model. I create a sliding-window view of an array, if I create it in numpy (using numpy.lib.stride_tricks.sliding_window_view) and than call torch.tensor, I get the warning, if I create it in torch using t.unfold I don’t get a warning. Is there a fundamental difference between the 2 methods?

From the warning:

This means writing to this tensor will result in undefined behavior. You may want to copy the array to protect its data or make it writable before converting it to a tensor.

If you don’t plan on writing to the tensor, which shares the underlying data with the numpy array, you could ignore the warning.

1 Like