Are numpy arrays passed by reference?

前端 未结 3 1769
轮回少年
轮回少年 2020-12-07 11:17

I came across the fact that numpy arrays are passed by reference at multiple places, but then when I execute the following code, why is there a difference betwe

3条回答
  •  广开言路
    2020-12-07 11:55

    The first function calculates (arr - 3), then assigns the local name arr to it, which doesn't affect the array data passed in. My guess is that in the second function, np.array overrides the -= operator, and operates in place on the array data.

提交回复
热议问题