三秒搞清楚:numpy两种展平方法(ravel、flatten)的区别

结合代码,三秒搞清楚

import numpy as np
a = np.arange(5).reshape(-1, 1)
b = a.ravel()
c = a.flatten()
a[0] = 2  # 对a进行修改

修改a时,b发生了变化

>>> b
array([2, 1, 2, 3, 4])

修改a时,c并未发生变化

>>> c
array([0, 1, 2, 3, 4])

猜你喜欢

转载自blog.csdn.net/shiyuzuxiaqianli/article/details/115678678