NumPy arrays
Vectors and matrices are not available in core Python. In order to use them, you will have to import the NumPy library. Just as how you used dot notation to access methods of an object,
you can use the dot notation to access functions from a library. Recall that you can import a library using an alias. For example, to import package
as pk
, you can use:
import package as pk
Within the numpy library, you can use the loadtxt()
function to import files.
For example, you can load a file named data.csv
using numpy with numpy.loadtxt('data.csv')
. The loadtxt()
function has a delimiter
parameter which lets you specify that your data is separated by commas.
This exercise is part of the course
Python for R Users
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import the numpy library using the alias: np
____ ____ ____ ____