矩阵连接

1. np.concatenate连接矩阵,然后reshape

import numpy as np
x1 = np.array([[1,1],
     [1,1]])
x2 = np.array([[2,2],[2,2]])
x3 = np.concatenate((x1,x2))
x3 = x3.reshape((x1.shape[0],2)+x1.shape[1:])
print x3.shape
#(2,2,2)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

2. list相加和list.append()

    colname_sum = ['date']
    colname_sum= colname_sum + (list(range(2)))
    #['date', 0, 1]
    colname_append = ['date']
    colname_append.append(list(range(2)))
    #['date', [0, 1]]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

3. dataframe.copy()

df1 = df2 #cite
df1 = df2.copy() #copy
  • 1
  • 2

4. df colname

    col = range(5)
    col.append('label')
    df = pd.DataFrame(columns=col)
  • 1
  • 2
  • 3

4. swap col

cols = list(df)
cols.insert(0, cols.pop(cols.index('object')))
df = df.ix[:, cols]
  • 1
  • 2
  • 3

5. big endian&& min_max_scaler && img from array

raw = np.fromfile('c1_1.raw', dtype=np.int8)

raw = np.ndarray(shape = (1081, 2571),dtype='>i2', buffer=raw)

min_max_scaler = preprocessing.MinMaxScaler(feature_range=(0,255),copy=True)
raw = min_max_scaler.fit_transform(raw)
raw_img = Image.fromarray(raw)

#PIL cannot write mode F to jpeg
if raw_img.mode != 'RGB':
  #  raw_img = raw_img.convert('RGB')
    raw_img = raw_img.convert('L')

猜你喜欢

转载自blog.csdn.net/sinat_39372048/article/details/81012284