python notes

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)

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]]

3. dataframe.copy()

df1 = df2 #cite
df1 = df2.copy() #copy

4. df colname

    col = range(5)
    col.append('label')
    df = pd.DataFrame(columns=col)

4. swap col

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

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')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值