特征图滚动与索引K (1)

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import tensorflow as tf
import tensorflow.keras as keras
import tensorflow.keras.layers as layers
a = [1,2,3,4]
b = [5,6,7,8]
c = [9,10,11,12]
d = [13,14,15,16]
abcd = np.c_[a,b,c,d]
abcd
array([[ 1,  5,  9, 13],
       [ 2,  6, 10, 14],
       [ 3,  7, 11, 15],
       [ 4,  8, 12, 16]])

pd_ = pd.DataFrame(abcd,columns=[‘a’, ‘b’, ‘c’,‘d’])
pd_

pd_ = pd.DataFrame(abcd)
pd_
0123
015913
1261014
2371115
3481216
qqq = pd_.to_dict('list')
qqq
{0: [1, 2, 3, 4], 1: [5, 6, 7, 8], 2: [9, 10, 11, 12], 3: [13, 14, 15, 16]}
ppp = pd_.to_dict('split')
ppp
{'index': [0, 1, 2, 3],
 'columns': [0, 1, 2, 3],
 'data': [[1, 5, 9, 13], [2, 6, 10, 14], [3, 7, 11, 15], [4, 8, 12, 16]]}
rrr = pd_.to_dict('records')
rrr
[{0: 1, 1: 5, 2: 9, 3: 13},
 {0: 2, 1: 6, 2: 10, 3: 14},
 {0: 3, 1: 7, 2: 11, 3: 15},
 {0: 4, 1: 8, 2: 12, 3: 16}]
sss = pd_.to_dict('index')
sss
{0: {0: 1, 1: 5, 2: 9, 3: 13},
 1: {0: 2, 1: 6, 2: 10, 3: 14},
 2: {0: 3, 1: 7, 2: 11, 3: 15},
 3: {0: 4, 1: 8, 2: 12, 3: 16}}
ttt = pd_.to_dict()
ttt
{0: {0: 1, 1: 2, 2: 3, 3: 4},
 1: {0: 5, 1: 6, 2: 7, 3: 8},
 2: {0: 9, 1: 10, 2: 11, 3: 12},
 3: {0: 13, 1: 14, 2: 15, 3: 16}}
for i,j in qqq.items():
    print(i)
    print(j)
0
[1, 2, 3, 4]
1
[5, 6, 7, 8]
2
[9, 10, 11, 12]
3
[13, 14, 15, 16]

滚动

abcd_ = np.roll(abcd,shift = (3,2),axis=(0,1))
abcd_
array([[10, 14,  2,  6],
       [11, 15,  3,  7],
       [12, 16,  4,  8],
       [ 9, 13,  1,  5]])
pd_ = pd.DataFrame(abcd)
pd_
0123
015913
1261014
2371115
3481216
qqq = pd_.to_dict('list')
qqq
{0: [1, 2, 3, 4], 1: [5, 6, 7, 8], 2: [9, 10, 11, 12], 3: [13, 14, 15, 16]}
class CyclicShift(keras.layers.Layer):
    def __init__(self, displacement_1,displacement_2):
        super().__init__()
        self.displacement_1 = displacement_1
        self.displacement_2 = displacement_2

    def call(self, x):
        return tf.roll(x, shift = (self.displacement_1,self.displacement_2), axis=(1,2))
XXX = np.array([[[3,4,5],[6,7,8]],
               [[9,10,11],[12,13,14]]])

CyclicShift(1,2)(XXX)
<tf.Tensor: shape=(2, 2, 3), dtype=int32, numpy=
array([[[ 7,  8,  6],
        [ 4,  5,  3]],

       [[13, 14, 12],
        [10, 11,  9]]])>
XXX
array([[[ 3,  4,  5],
        [ 6,  7,  8]],

       [[ 9, 10, 11],
        [12, 13, 14]]])
CyclicShift(1,0)(XXX)
<tf.Tensor: shape=(2, 2, 3), dtype=int32, numpy=
array([[[ 6,  7,  8],
        [ 3,  4,  5]],

       [[12, 13, 14],
        [ 9, 10, 11]]])>
CyclicShift(0,2)(XXX)
<tf.Tensor: shape=(2, 2, 3), dtype=int32, numpy=
array([[[ 4,  5,  3],
        [ 7,  8,  6]],

       [[10, 11,  9],
        [13, 14, 12]]])>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

潘诺西亚的火山

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值