2012-06-05 25 views
22

它似乎是某種水平連接,但我在網上找不到任何文檔。這裏最小的工作例如:c下劃線表達式`c_`做了什麼?

In [1]: from numpy import c_ 
In [2]: a = ones(4) 
In [3]: b = zeros((4,10))  
In [4]: c_[a,b] 
Out[4]: 
array([[ 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], 
     [ 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], 
     [ 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], 
     [ 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]]) 
+6

頂部提示:在IPython中,你可以使用''得到任何對象的更多信息?嘗試運行'c_?'。 –

+0

@ThomasK,謝謝,那正是我所需要的。 C_?爲我提供了所有的信息。你能發表一個答案,以便我可以選擇它嗎? – Framester

+0

最簡單的參考是numpy手冊:http://docs.scipy.org/doc/numpy/reference/generated/numpy.c_.html(適用於沒有IPython的所有人)。 – strpeter

回答

24

使用IPython中的?語法來獲得更多的信息:

In [2]: c_? 
Type:  CClass 
Base Class: <class 'numpy.lib.index_tricks.CClass'> 
String Form:<numpy.lib.index_tricks.CClass object at 0x9a848cc> 
Namespace: Interactive 
Length:  0 
File:  /usr/lib/python2.7/dist-packages/numpy/lib/index_tricks.py 
Docstring: 
Translates slice objects to concatenation along the second axis. 

This is short-hand for ``np.r_['-1,2,0', index expression]``, which is 
useful because of its common occurrence. In particular, arrays will be 
stacked along their last axis after being upgraded to at least 2-D with 
1's post-pended to the shape (column vectors made out of 1-D arrays). 

For detailed documentation, see `r_`. 

Examples 
-------- 
>>> np.c_[np.array([[1,2,3]]), 0, 0, np.array([[4,5,6]])] 
array([[1, 2, 3, 0, 0, 4, 5, 6]]) 
+0

男子我甚至猜不出有多少次早點認識這個簡單的'?'會節省時間。 – javadba

相關問題