python的np.nonzero返回的到底是元组还是nparray
代码如下:
import numpy as np
for i in range(1):
a=np.zeros((7,7))
a[1][2] = 50;
a[1][4] = 40;
a[1][5] = 25;
a[1][6] = 10;
a[2][3] = 15;
a[2][4] = 20;
a[2][6] = 25;
a[3][4] = 10;
a[3][5] = 20;
a[4][5] = 10;
a[4][6] = 25;
a[5][6] = 55;
a2 = a.astype(‘i’)
suoyin = np.nonzero(a[1,:] != 0)
print(type(suoyin))
print(suoyin)
# print(len(list(suoyin)))
for i in suoyin:
print(i)
结果:
<class ‘tuple’>
(array([2, 4, 5, 6], dtype=int64),)
[2 4 5 6]
问题一:np.nonzero函数返回的是元组还是array
问题二:为什么suoyin可以为[2 4 5 6],这么有空格
问题三:为什么for循环只循环一次
求各位大佬带带我!!