Python functions in Julia
Now that you have imported the math package from Python in the previous exercise using PythonCall, you can begin to call functions from the package.
You have imported math using the alias pymath, so when calling functions from math, prefix the function with pymath. This makes it clear that you are using an imported Python version of the package.
Este exercício faz parte do curso
Intermediate Julia
Instruções do exercício
- Define a vector
xcontaining the values from negative three to three in increments of one, including zero, as you normally would using Julia's square bracket syntax. - Use the Python function
fabsin themathpackage to get the absolute value of the second value inx. - Use the Python function
powin themathpackage to raise the sixth value ofxto the seventh value ofx.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
using PythonCall
pymath = pyimport("math")
# Define a vector x from -3 to 3
x = ____
# Print the absolute value of the second value in x using pymath
println(____.____(____))
# Print the sixth value of x raised to the power of the 7th value of x
println(____.____(x[6], ____))