numpy.ones_like(a, dtype=None, order='K', subok=True)
返回与给定数组shape相同,且值均为1的数组。
- 如果设置dtype的话,返回数据类型为dtype,否则为a的类型
- 另外两个参数可忽略(不懂)
np.zeros_like
返回与给定数组shape相同,且值均为0的数组。
>>>arr = np.arange(9).reshape(3,3)
>>>arr
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
>>>np.ones_like(arr)
array([[1, 1, 1],
[1, 1, 1],
[1, 1, 1]])
>>>np.zeros_like(arr)
array([[0, 0, 0],
[0, 0, 0],
[0, 0, 0]])