【发布时间】:2021-09-14 14:02:01
【问题描述】:
您好,我正在阅读 https://nnfs.io/ 这本书,但使用的是 JuliaLang(更好地了解该语言并更频繁地使用它是一种自我挑战。而不是在 Python 中做同样的事情。)
我遇到过他们自定义编写了一些函数的书的一部分,我需要在 JuliaLang 中重新创建它...
来源:https://cs231n.github.io/neural-networks-case-study/
蟒蛇
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
# lets visualize the data:
plt.scatter(X[:, 0], X[:, 1], c=y, s=40, cmap=plt.cm.Spectral)
plt.show()
到目前为止我的 julia 版本....
N = 100 # Number of points per class
D = 2 # Dimensionality
K = 3 # Number of classes
X = zeros((N*K, D))
y = zeros(UInt8, N*K)
# See https://docs.julialang.org/en/v1/base/math/#Base.range
for j in range(0,length=K)
ix = range(N*(j), length = N+1)
radius = LinRange(0.0, 1, N)
theta = LinRange(j*4, (j+1)*4, N) + randn(N)*0.2
X[ix] = ????????
end
请注意 ??????? 区域,因为我现在正试图破译 Julia 是否有这个 numpy 函数的等价物
https://numpy.org/doc/stable/reference/generated/numpy.c_.html
感谢任何帮助.. 或者告诉我是否需要自己写一些东西
【问题讨论】:
-
您可以尝试编写
for循环来执行您想要的操作,而不是搜索函数。有时直接的方法是最好的方法。
标签: arrays algorithm matrix julia