import numpy as np
def get_mean(feature1, feature2):
'''
将feature1和feature2横向拼接,然后统计拼接后的ndarray中每列的均值
:param feature1:待`hstack`的`ndarray`
:param feature2:待`hstack`的`ndarray`
:return:类型为`ndarray`,其中的值`hstack`后每列的均值
'''
#********* Begin *********#
return np.mean(np.hstack((feature1,feature2)), 0)
#********* End *********#
第2关:比较、掩码和布尔逻辑
import numpy as np
def student(num,input_data):
result=[]
# ********* Begin *********#
a = np.array(input_data)
result = a[a > num]
# ********* End *********#
return result
第3关:花式索引与布尔索引
import numpy as np
def student(input_data):
result=[]
#********* Begin *********#
a = np.array(input_data)
result = a[(a>='A')&(a<='Z')]
# ********* End *********#
return result
第4关:广播机制
import numpy as np
def student(a,b,c):
result=[]
# ********* Begin *********#
a = np.array(a)
b = np.array(b)
c = np.array(c)
result = a + b + c
# ********* End *********#
return result
5关:线性代数
from numpy import linalg
import numpy as np
def student(input_data):
'''
将输入数据筛选性别为男,再进行线性方程求解
:param input_data:类型为`list`的输入数据
:return:类型为`ndarray`
'''
result=[]
# ********* Begin *********#
a = np.array(input_data)
x=[]
y=[]
for i in a:
if i[0]=="男":
x.append([int(i[1]),int(i[2])])
y.append([int(i[-1])])
if x==[] and y==[]:
return result
x=np.array(x)
y=np.array(y)
result=linalg.solve(x,y)
# ********* End *********#
return result