其他分享
首页 > 其他分享> > numpy作业3

numpy作业3

作者:互联网

import numpy as np
x = np.array([[1,2,3],[4,5,6],[1,2,3]])
x.flatten()
x.ravel()
x.flatten('F')
x.flatten()[1] = 20
x
x.ravel()[1] = 20
x
x.reshape(1,-1)


array([[ 1, 20,  3,  4,  5,  6,  1,  2,  3]])
x = np.array([[1,2,3],[2,3,4]])
np.prod(x)
np.prod(x,axis=1)
np.prod(x,axis=0)
array([ 2,  6, 12])
x = np.array([[1,2,3],[-3,2,4],[5,-2,9]])
x
y1 = np.maximum(0,x) # 把小于0的元素置0,比改变x的值
y1
y2 = np.minimum(0,x) # 把大于0的元素置0,不改变x的值
y2
x1 = x.copy()
x1
x1[x1 < 0] = 0 # 把小于0的元素置0,改变x1的值
x1
x2 = x.copy()
x2[x2 > 0] = 0 # 把大于0的元素置0,改变x2的值
x
y1
y2
x1
x2

标签:y1,作业,x2,flatten,np,array,x1,numpy
来源: https://blog.csdn.net/yangmaoda/article/details/120092506