python - What does the c underscore expression `c_` do exactly? -
it seems kind of horizontal concatenation, not find documentation online. here minimal working example:
in [1]: numpy import c_ in [2]: = 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.]])
use ipython's ? syntax more information:
in [2]: c_? type: cclass base class: <class 'numpy.lib.index_tricks.cclass'> string form:<numpy.lib.index_tricks.cclass object @ 0x9a848cc> namespace: interactive length: 0 file: /usr/lib/python2.7/dist-packages/numpy/lib/index_tricks.py docstring: translates slice objects concatenation along second axis. short-hand ``np.r_['-1,2,0', index expression]``, useful because of common occurrence. in particular, arrays stacked along last axis after being upgraded @ least 2-d 1's post-pended shape (column vectors made out of 1-d arrays). 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]])
Comments
Post a Comment