I need to translate these two lines to mathematica from python
gamma = np.array([u/np.linalg.norm(u) for u in x[:y]])
beta = np.array([u/np.linalg.norm(u) for u in x[y:]])
where y is a number.
:
in python denotes ranges of array elements, and is equivalent to Span
(;;
) as noted by Henrik Schumacher's comment above
Note that Mathematica indexes from 1, whereas Python indexes from zero; additionally the array range specification in Python has the last term as an "up to but not including", whereas in Mathematica, it is inclusive of that element (as noted in Roman's comment above)
As best I understand your problem, it looks something like:
gamma = Norm/@x[[;;y-1]]
beta = Norm/@x[[y;;]]
But check your array indexing convention to make sure that the upper and lower bounds are what you intend them to be.
Span
. $\endgroup$a[x:y]
means taking elementsx
toy-1
, where the first element is element zero. Mathematicaa[[x;;y]]
means taking elementsx
toy
, where the first element is element 1. So Pythona[x:y]
should be written asa[[x+1;;y]]
in Mathematica. $\endgroup$