Untitled

import numpy as np
a = np.array([1,1,1,1])
b = np.array([[1],[1],[1],[1]])
a+b
array([[2, 2, 2, 2],
       [2, 2, 2, 2],
       [2, 2, 2, 2],
       [2, 2, 2, 2]])
import numpy as np
a = np.array([1,1,1,1])
b = np.array([[1],[1],[1],[1]])
a+b
c = np.array([[1,1,1,1]])
c+b
array([[2, 2, 2, 2],
       [2, 2, 2, 2],
       [2, 2, 2, 2],
       [2, 2, 2, 2]])
W = np.array([[1,1,1],[2,2,2]])
W[:,1]
array([1, 2])
import numpy as np
matrix = [
[1,2,3,4],
[5,6,7,8],
[9,10,11,12]
]
p1 = np.delete(matrix, 1, 0) 
print('>>>>p1>>>>\n',p1)
p2 = np.delete(matrix, 1, 1) 
print('>>>>p2>>>>\n',p2)
p3 = np.delete(matrix, 1) 
print('>>>>p3>>>>\n',p3)
p4 = np.delete(matrix, [0,1], 1) 
print('>>>>p4>>>>\n',p4)
>>>>p1>>>>
 [[ 1  2  3  4]
 [ 9 10 11 12]]
>>>>p2>>>>
 [[ 1  3  4]
 [ 5  7  8]
 [ 9 11 12]]
>>>>p3>>>>
 [ 1  3  4  5  6  7  8  9 10 11 12]
>>>>p4>>>>
 [[ 3  4]
 [ 7  8]
 [11 12]]
import numpy as np
matrix = [
[1,2,3,4],
[5,6,7,8],
[9,10,11,12]
]
q1 = np.insert(matrix, 1, [1,1,1,1], 0) # 第0维度(行)第1行添加[1,1,1,1]
print('>>>>q1>>>>\n',q1)
q2 = np.insert(matrix, 0, [1,1,1], 1) # 第1维度(列)第0列添加1,1,1
print('>>>>q2>>>>\n',q2)
q3 = np.insert(matrix, 3, [1,1,1,1], 0) # 第0维度(行)第3行添加[1,1,1,1]
print('>>>>q3>>>>\n',q3)
>>>>q1>>>>
 [[ 1  2  3  4]
 [ 1  1  1  1]
 [ 5  6  7  8]
 [ 9 10 11 12]]
>>>>q2>>>>
 [[ 1  1  2  3  4]
 [ 1  5  6  7  8]
 [ 1  9 10 11 12]]
>>>>q3>>>>
 [[ 1  2  3  4]
 [ 5  6  7  8]
 [ 9 10 11 12]
 [ 1  1  1  1]]
import numpy as np
matrix = [
[1,2,3,4],
[5,6,7,8],
[9,10,11,12]
]
m1 = np.append(matrix,[[1,1,1,1]],axis=0)
print('>>>>m1>>>>\n',m1)
m2 = np.append(matrix,[[1],[1],[1]],axis=1)
print('>>>>m2>>>>\n',m2)
m3 = np.append(matrix,[1,1,1,1])
print('>>>>m3>>>>\n',m3)
>>>>m1>>>>
 [[ 1  2  3  4]
 [ 5  6  7  8]
 [ 9 10 11 12]
 [ 1  1  1  1]]
>>>>m2>>>>
 [[ 1  2  3  4  1]
 [ 5  6  7  8  1]
 [ 9 10 11 12  1]]
>>>>m3>>>>
 [ 1  2  3  4  5  6  7  8  9 10 11 12  1  1  1  1]
x = np.array([[1,2,3],[2,3,4]])
np.prod(x)
144
import numpy as np
n = np.random.rand(3,4)
n
array([[ 0.79630367,  0.67210121,  0.77396386,  0.28233989],
       [ 0.20420985,  0.95436753,  0.68191202,  0.98143148],
       [ 0.79416961,  0.0454998 ,  0.2843794 ,  0.17029415]])
import numpy as np
x = np.random.randn(2,3)
x
array([[-1.03081723,  0.52731215,  0.94021586],
       [ 0.4081628 ,  0.27924502, -1.16727873]])
import numpy as np
c = np.array([[1,2],[3,4]])
c
c.astype(np.float32)
array([[ 1.,  2.],
       [ 3.,  4.]], dtype=float32)
import numpy as np
x = np.array([1,3,5])
y = np.array([4,6])
XX,YY = np.meshgrid(x,y)
XX
array([[1, 3, 5],
       [1, 3, 5]])
import numpy as np
x = np.array([[3,4,5],[1,3,4]])
y = np.array([[1,1,1],[2,2,2]])
np.hstack((x,y)) 
array([[3, 4, 5, 1, 1, 1],
       [1, 3, 4, 2, 2, 2]])
import numpy as np
a = np.array([0.125,0.568,5.688])
np.round(a)
array([ 0.,  1.,  6.])
import numpy as np
a = np.array([[1,2,3],[4,5,6]])
a = np.array([[1,2,3,6],[4,5,6,6]])
a1 = a.reshape((1,2,4))
a1
array([[[1, 2, 3, 6],
        [4, 5, 6, 6]]])

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值