第一次作业(本篇文章+前四篇文章)

import numpy as np
c=np.array([[1,2],[3,4]])
c
array([[1, 2],
       [3, 4]])
c.astype(np.float32)
array([[1., 2.],
       [3., 4.]], dtype=float32)

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]])
np.vstack((x,y))
array([[3, 4, 5],
       [1, 3, 4],
       [1, 1, 1],
       [2, 2, 2]])

y=np.array([4,6])
XX,YY=np.meshgrid(x,y)
XX
array([[1, 3, 5],
       [1, 3, 5]])
YY
array([[4, 4, 4],
       [6, 6, 6]])

import numpy as np
c=np.array([1,2,5,4])
c[:,np.newaxis]
array([[1],
       [2],
       [5],
       [4]])
c[np.newaxis,:]
array([[1, 2, 5, 4]])

import numpy as np
A= np.arange(95,99).reshape(2,2)
A
array([[95, 96],
       [97, 98]])
np.pad(A,((3,2),(2,3)),'constant',constant_values=(0,0))
array([[ 0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0],
       [ 0,  0, 95, 96,  0,  0,  0],
       [ 0,  0, 97, 98,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0]])
b=np.array([[[1,2],[3,4]],[[3,4],[7,8]],[[4,5],[1,2]]])
b
array([[[1, 2],
        [3, 4]],

       [[3, 4],
        [7, 8]],

       [[4, 5],
        [1, 2]]])
np.pad(b,((0,0),(1,1),(1,1)),'constant' ,constant_values = 0)
array([[[0, 0, 0, 0],
        [0, 1, 2, 0],
        [0, 3, 4, 0],
        [0, 0, 0, 0]],

       [[0, 0, 0, 0],
        [0, 3, 4, 0],
        [0, 7, 8, 0],
        [0, 0, 0, 0]],

       [[0, 0, 0, 0],
        [0, 4, 5, 0],
        [0, 1, 2, 0],
        [0, 0, 0, 0]]])

import numpy as np
x = np.array([[1,2,3],[4,5,6]])
np.zeros_like(x)
array([[0, 0, 0],
       [0, 0, 0]])

import numpy as np
a=np.array([0.125,0.568,5.688])
np.round(a)
array([0., 1., 6.])
np.round(a,decimals=2)
array([0.12, 0.57, 5.69])
np.floor(a)
array([0., 0., 5.])
np.ceil(a)
import numpy as np
x = np.array([[1,2,3],[-3,2,4],[5,-2,9]])
x
array([[ 1,  2,  3],
       [-3,  2,  4],
       [ 5, -2,  9]])
x1 = x.copy() 
x1[x1 > 0] = 0
x1
array([[ 0,  0,  0],
       [-3,  0,  0],
       [ 0, -2,  0]])
x
array([[ 1,  2,  3],
       [-3,  2,  4],
       [ 5, -2,  9]])
x2 = x
x2
array([[ 1,  2,  3],
       [-3,  2,  4],
       [ 5, -2,  9]])
x2[x2>0] = 0
x2
array([[ 0,  0,  0],
       [-3,  0,  0],
       [ 0, -2,  0]])
x 
array([[ 0,  0,  0],
       [-3,  0,  0],
       [ 0, -2,  0]])
x = np.array([[1,2,3],[-3,2,4],[5,-2,9]])
x3 = x[2]
x3
array([ 5, -2,  9])
x3[2] = 100 
x
array([[  1,   2,   3],
       [ -3,   2,   4],
       [  5,  -2, 100]])

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]]])
b=np.array([[3,4,5,6],[1,2,3,4],[4,5,5,5]])
b
array([[3, 4, 5, 6],
       [1, 2, 3, 4],
       [4, 5, 5, 5]])
b1=b.reshape((1,3,4)).transpose((1,0,2))
b1
array([[[3, 4, 5, 6]],

       [[1, 2, 3, 4]],

       [[4, 5, 5, 5]]])
a1
array([[[1, 2, 3, 6],
        [4, 5, 6, 6]]])
a1+b1
array([[[ 4,  6,  8, 12],
        [ 7,  9, 11, 12]],

       [[ 2,  4,  6, 10],
        [ 5,  7,  9, 10]],

       [[ 5,  7,  8, 11],
        [ 8, 10, 11, 11]]])

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值