python中多維陣列ndarray合并,pythonndarray

來源:互聯網
上載者:User

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.