References:
In [1]:
import array
In [2]:
array_one = array.array('i',[1,2,3,4])
type(array_one)
In [3]:
type(array_one[0])
Out[3]:
In [4]:
import numpy as np
np.__version__
Out[4]:
In [5]:
list_one = [1,2,3,4,5]
In [6]:
numpy_array = np.array(list_one)
type(numpy_array)
Out[6]:
In [7]:
numpy_array
Out[7]:
In [8]:
list_two = [1,2,3,4,5]
# The following will throw an error:
list_two + 2
In [9]:
for index, item in enumerate(list_two):
list_two[index] = item + 2
list_two
Out[9]:
In [10]:
numpy_array
Out[10]:
In [11]:
numpy_array + 2
Out[11]:
In [12]:
numpy_array_one = np.array([1,2])
numpy_array_two = np.array([4,6])
In [13]:
numpy_array_one + numpy_array_two
Out[13]:
In [14]:
numpy_array_one > numpy_array_two
Out[14]:
In [15]:
import numpy as np
import sys
In [16]:
python_list = [1,2,3,4,5,6]
python_list_size = sys.getsizeof(1) * len(python_list)
python_list_size
Out[16]:
In [17]:
python_numpy_array = np.array([1,2,3,4,5,6])
python_numpy_array_size = python_numpy_array.itemsize * python_numpy_array.size
python_numpy_array_size
Out[17]:
In [18]:
numpy_array
Out[18]:
In [19]:
numpy_array[1]
Out[19]:
In [20]:
numpy_array[1:4]
Out[20]:
In [21]:
numpy_array_slice = numpy_array[1:4]
numpy_array_slice
Out[21]:
In [22]:
numpy_array_slice[1] = 10
numpy_array_slice
Out[22]:
In [23]:
numpy_array
Out[23]:
In [24]:
numpy_two_dimensional_array = np.array([[1,2,3],[4,5,6],[7,8,9]])
In [25]:
numpy_two_dimensional_array
Out[25]:
In [26]:
numpy_two_dimensional_array[1]
Out[26]:
In [27]:
numpy_two_dimensional_array[1][2]
Out[27]:
In [28]:
numpy_two_dimensional_array[1,2]
Out[28]:
In [29]:
numpy_two_dimensional_array
Out[29]:
In [30]:
numpy_two_dimensional_array[:1]
Out[30]:
In [31]:
numpy_two_dimensional_array[:2]
Out[31]:
In [32]:
numpy_two_dimensional_array[:3]
Out[32]:
In [33]:
numpy_two_dimensional_array[:2,1:]
Out[33]:
In [34]:
numpy_two_dimensional_array[:2,:1]
Out[34]:
In [35]:
numpy_two_dimensional_array[2][1:]
Out[35]:
In [ ]: