computing star

2013年12月18日

快速取出matrix diagonal element方法

n = 1000
c = 20
a = np.random.rand(n,n)

a[np.diag_indices_from(a)] /= c # 119 microseconds
a.flat[::n+1] /= c # 25.3 microseconds
 
#取出off diagonal的方法
 np.delete(a, a.ravel()[::n+1])
張貼者: computing star 於 晚上7:10
標籤: Python
較新的文章 較舊的文章 首頁

About me

我的相片
computing star
Kaohsiung, Taiwan
檢視我的完整簡介

Tags

  • 平行處理 (5)
  • 伺服器設定 (2)
  • ACM (1)
  • algorithm (3)
  • blog (1)
  • C++ (6)
  • database (4)
  • django (1)
  • investment (4)
  • Latex (1)
  • Linux (20)
  • machine learning (4)
  • MPI (1)
  • optimization (1)
  • postgres (5)
  • Python (21)
  • R (1)
  • Web (2)

網誌存檔

  • ►  2015 (10)
    • ►  12月 (1)
    • ►  11月 (2)
    • ►  6月 (6)
    • ►  3月 (1)
  • ►  2014 (4)
    • ►  11月 (1)
    • ►  6月 (2)
    • ►  3月 (1)
  • ▼  2013 (14)
    • ▼  12月 (4)
      • Gentoo編譯scipy(with intel MKL)
      • 快速取出matrix diagonal element方法
      • iptables保存
      • fast rolling window
    • ►  10月 (1)
    • ►  8月 (1)
    • ►  5月 (1)
    • ►  3月 (2)
    • ►  2月 (1)
    • ►  1月 (4)
  • ►  2012 (3)
    • ►  12月 (3)
  • ►  2011 (16)
    • ►  10月 (2)
    • ►  9月 (3)
    • ►  8月 (5)
    • ►  4月 (1)
    • ►  1月 (5)
  • ►  2010 (9)
    • ►  12月 (2)
    • ►  11月 (5)
    • ►  9月 (1)
    • ►  8月 (1)
  • ►  2009 (7)
    • ►  9月 (1)
    • ►  2月 (4)
    • ►  1月 (2)
  • ►  2008 (4)
    • ►  9月 (1)
    • ►  4月 (3)
頂尖企業主題. 技術提供:Blogger.