python中多維陣列ndarray合并,pythonndarray
http://blog.csdn.net/pipisorry/article/details/39215089
numpy中ndarray的多維度上的合并
實現matlab data1=[r.*cos(t),r.*sin(t)];的功能:
實現matlab data=[data1;data2];的功能
data_pos =
[[-0.00870993 0.84913981]
[-0.28528784 0.2612078 ]
[-0.4475744 0.43677346]
[-0.2473318 -0.89767194]
[ 0.45242961 -0.02112013]
[-0.10939665 -0.67678242]
[ 0.59871918 -0.27938622]
[-0.67484345 0.18797474]
[ 0.04628507 -0.14074493]
[ 0.27405096 0.91563243]]
data_neg =
[[-1.7135893 -0.13973792]
[-1.69338611 0.4599861 ]
[ 0.4576769 1.68156328]
[ 0.1199849 -1.00716347]
[ 0.94074345 1.03022516]
[-0.68055284 -1.84048252]
[ 1.35995126 0.11136057]
[ 1.04061602 0.89650711]
[-1.79624533 0.27777414]
[ 0.78416735 1.47684656]]
data = np.append(data_pos, data_neg, axis = 0)
data =
[[ -5.96464404e-01 4.06034396e-01]
[ 4.82952945e-01 -1.20121194e-01]
[ -5.77977122e-01 -3.79254316e-01]
[ -7.38540595e-01 5.30272266e-01]
[ 1.51701741e-01 -2.33477263e-01]
[ -3.35472827e-04 4.38564615e-01]
[ -9.62188462e-01 2.36012802e-01]
[ 5.44815124e-01 -5.36231442e-01]
[ -2.76687718e-01 -3.30882444e-01]
[ 2.29255115e-01 -5.06503177e-01]
[ 3.26605661e-01 -1.86522383e+00]
[ 5.96712043e-01 1.46382588e+00]
[ 1.67364905e+00 9.05077496e-01]
[ -1.48502012e+00 -3.60574944e-01]
[ -1.44121871e+00 -1.33299063e+00]
[ 1.39996884e+00 1.79711008e-01]
[ -6.82403150e-02 -1.53043305e+00]
[ 4.25909366e-01 -1.10527802e+00]
[ -7.00656660e-01 8.22864651e-01]
[ -6.55652372e-01 -1.80101194e+00]]
from:http://blog.csdn.net/pipisorry/article/details/39215089
python的numpy中合并array
...這個問題不用糾結吧,你是一維的數組,可以直接強轉成list,直接加後再轉成array
python裡,怎合并相同的數組的值?
x=[['北京', 2], ['北京', 1], ['天津', 1], ['福建', 1]]
tmp = {}
for v in x:
tmp[v[0]] = tmp.get(v[0]) and tmp[v[0]] + v[1] or v[1]
x= [ [k, v] for (k, v) in tmp.items() ]
print(x)
輸出:
[['北京', 3], ['福建', 1], ['天津', 1]]