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_
0 1 2 3 0 1 5 9 13 1 2 6 10 14 2 3 7 11 15 3 4 8 12 16
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_
0 1 2 3 0 1 5 9 13 1 2 6 10 14 2 3 7 11 15 3 4 8 12 16
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]]])>