When I'm using Python + Numpy and when I'm using Julia, I've written a recent problem that often results in bad code (or rather doesn't work). Can anyone please give me a good idea?
--Tried with Anaconda 4.3.0 (64-bit), Python 3.6.0, IPython 5.1.0
import numpy as np
X = np.array([[1, 2, 3], [4, 5, 6]])
# X = np.matrix([[1, 2, 3], [4, 5, 6]])But about the same
for elem in X: print(elem)
#output
# [1 2 3](In the case of matrix[[1 2 3]])
# [4 5 6](In the case of matrix[[4 5 6]])
――I'm used to it, so I want you to do this.
--I tried it with Julia 0.5.0
X = [1 2 3; 4 5 6]
#output
# 2x3 Array{Int64, 2}:
# 1 2 3
# 4 5 6
for elem in X; println(elem); end
#output
# 1
# 4
# 2
# 5
# 3
# 6
――Personally, this iteration is not very intuitive (it can be called Python / Numpy brain), so I want to do something about it. --Originally Julia has a slow iteration of either Row or Column (I don't know the details) --Mass production of the following code with a feeling of dying
X = [1 2 3; 4 5 6]
m, n = size(X)
for i=1:m; println(X[i, :]); end
#output
――It works for the time being --Unpleasant reason: Mood
There are various discussions (although it is not old).
Recommended Posts