它似乎是某种横向连接,但我在网上找不到任何文档.这是一个最小的工作示例:
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.]])
Run Code Online (Sandbox Code Playgroud) Numpy.r _,.c_和.s_是我遇到的唯一一个在方括号而不是括号中使用参数的Python函数.为什么会这样?这些功能有什么特别之处吗?我可以创建自己的使用括号的功能(不是我想要的;只是好奇)?
例如,正确的语法是:
np.r_['0,2', [1,2,3], [4,5,6]]
Run Code Online (Sandbox Code Playgroud)
我原以为是:
np.r_('0,2', [1,2,3], [4,5,6])
Run Code Online (Sandbox Code Playgroud) 我来自C++背景,最近开始学习python.我正在研究索引和选择数据.我碰到.iloc[]的类Series,DataFrame并Panel在大熊猫库.我无法理解是什么.iloc?是功能还是属性?很多次我错误地使用()而[]不是得到实际结果(但它不会给我一个错误).
例:
In [43]: s = pd.Series(np.arange(5), index=np.arange(5)[::-1], dtype='int64')
In [44]: s[s.index.isin([2, 4, 6])]
Out[44]:
4 0
2 2
dtype: int64
In [45]: s.iloc(s.index.isin([2,4,6]))
Out[45]: <pandas.core.indexing._iLocIndexer at 0x7f1e68d53978>
In [46]: s.iloc[s.index.isin([2,4,6])]
Out[46]:
4 0
2 2
dtype: int64
Run Code Online (Sandbox Code Playgroud)
谁能告诉我在哪里学习更多关于这类运营商的信息.
嗨,我正在阅读这本书https://nnfs.io/但使用 JuliaLang (更好地了解该语言并更频繁地使用它是一个自我挑战......而不是在 Python 中做同样的事情......)
我发现书中的一部分他们自定义编写了一些函数,我需要在 JuliaLang 中重新创建它......
来源: https: //cs231n.github.io/neural-networks-case-study/
Python
N = 100 # number of points per class
D = 2 # dimensionality
K = 3 # number of classes
X = np.zeros((N*K,D)) # data matrix (each row = single example)
y = np.zeros(N*K, dtype='uint8') # class labels
for j in range(K):
ix = range(N*j,N*(j+1))
r = np.linspace(0.0,1,N) # radius
t = np.linspace(j*4,(j+1)*4,N) + np.random.randn(N)*0.2 # theta
X[ix] = np.c_[r*np.sin(t), r*np.cos(t)]
y[ix] = j
# …Run Code Online (Sandbox Code Playgroud)