- 论坛徽章:
- 0
|
本帖最后由 dahe_1984 于 2018-03-25 13:52 编辑
- import numpy as np
- import math
- a=np.random.randint(0,2,size=[20,20])
- print(a)
- x_a, y_a = a.shape
- def oneTriangle(list):
- tri=np.ones(list,dtype=int)
- tri_upper_no_diag=np.triu(tri,k=1)[::-1]
- tri_lower_no_diag=np.tril(tri,k=0)
- a=np.concatenate((tri_upper_no_diag,tri_lower_no_diag),axis=1)
- b=np.delete(a,0,axis=1)
- return b
- def subsearch(a, b):
- number = 0
- x_b, y_b = b.shape
- for i in range(0,a.shape[0]):
- for j in range(0,a.shape[1]):
- #print(i,j)
- c = a[i:(i+x_b), j:(j+y_b)]
- if((c.shape == b.shape) and ((c == b).all())):
- #print(c,'\n', b)
- number = number + 1
- return (number, x_b)
- min_value = min(x_a, y_a)
- for i in range(2, min_value):
- b = oneTriangle([i, i])
- #print(b)
- number = subsearch(a, b)
- print(number)
复制代码
|
|