Create arrays in Numpy
Create arrays in Numpy

Creating arrays

In [63]:
import numpy as np
In [3]:
# create a 1D numpy array using np.array(list)
lst = [1, 4, 5, 8]
array = np.array(lst, float)
print array
[ 1.  4.  5.  8.]
In [7]:
# create a 2D numpy array
lst_2 = [[1, 2, 3], [4, 5, 6]]
array = np.array(lst_2, float)
In [9]:
# this is a list
# just that it's a list of lists
type(lst_2)
Out[9]:
list
Tags: numpy