tree = 6
for i in range(6):
print(" " * tree , end = '*' )
print('*'*2*i)
tree -=1
* *** ***** ******* ********* ***********
tree = 10
z = tree + 2
x = 1
for n in range(0,tree):
for n in range(0,z):
print(' ', end = '')
for n in range(0,x):
print('* ', end = '')
x= x + 1
z = z -1
print()
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
import math
for n in range(0,9):
i = math.floor(n/2)
s = math.floor((9-n)/2)
if (n/2).is_integer():
tree_even = ' '*s + '*'*i + ' ' + '*'*i + ' '*s
print(tree_even)
else:
tree_odd = ' '*s + '*'*n + ' '*s
print(tree_odd)
print(' !! ')
* * * *** ** ** ***** *** *** ******* **** **** !!
i = 0
star = '*'
tree_size = 12
trunk = 3
while i < tree_size:
print(star.center(40))
star += '**'
i += 1
while i < (tree_size + trunk):
print('***'.center(40))
i = i +1
* *** ***** ******* ********* *********** ************* *************** ***************** ******************* ********************* *********************** *** *** ***
rows = 5
for i in range(rows+1):
for j in range(i):
print(i, end = '')
print('')
1 22 333 4444 55555
list_number = [1,2,3,4,5,6,7,8,9]
i = 10
for number in range(9):
print((int((i-1)/2))*'+', str(number)*number + (int((i+1)/2))*'+')
i -= 1
++++ +++++ ++++ 1+++++ +++ 22++++ +++ 333++++ ++ 4444+++ ++ 55555+++ + 666666++ + 7777777++ 88888888+
fruits = ['bananas', 'apples', 'cherry']
for x in fruits:
if x == 'bananas':
continue
print(x)
apples cherry
i = 0
while i < 6:
i = i + 1
if i == 3:
continue
print(i)
1 2 4 5 6
fruits = ['bananas', 'apples', 'cherry']
for x in fruits:
print(x)
if x == 'apples':
break
bananas apples
i = 1
while i < 6:
print(i)
if i == 3:
break
i += 1
1 2 3
mylist = []
for x in [1,2,3]:
pass
mylist
[]
mylist = []
for x in [1,2,3]:
break
mylist.append(x)
mylist
[]
persons = ['Jon', 'Pete', 'Mary']
food = ['Japanese', 'Mexican', 'French']
for person in persons:
for restaurant in food:
print(person + ' eats in ' + restaurant)
Jon eats in Japanese Jon eats in Mexican Jon eats in French Pete eats in Japanese Pete eats in Mexican Pete eats in French Mary eats in Japanese Mary eats in Mexican Mary eats in French
num = float(input('Enter a number:'))
if (type(num) != int):
print('Not a number please try again')
if num >= 0:
if num == 0:
print('Number is zero')
else:
print('Positive')
if num < 0:
print('Number is negative')
Enter a number:14 Not a number please try again
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-47-e3c5748c4fac> in <module> 4 print('Not a number please try again') 5 ----> 6 if num >= 0: 7 if num == 0: 8 print('Number is zero') TypeError: '>=' not supported between instances of 'str' and 'int'
float('14')
14.0
def print_greeting():
print('Hello students!')
print_greeting()
Hello students!
def print_date(month, day , year):
joined = str(year) + '/' + str(month) +'/' + str(day)
print(joined)
print_date(8,13,2021)
2021/8/13
def averages(values):
if len(values) == 0:
return None
return(sum(values)/len(values))
averages([5,6,7,10])
7.0
averages('hello')
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-63-624559abe31e> in <module> ----> 1 averages('hello') <ipython-input-61-97af3c6a5d68> in averages(values) 2 if len(values) == 0: 3 return None ----> 4 return(sum(values)/len(values)) TypeError: unsupported operand type(s) for +: 'int' and 'str'
def birthday_func(month, date):
print('My birthday is on the month of : '+ str(month))
print('My birthday is on the : ' + str(date))
birthday_func(7,14)
My birthday is on the month of : 7 My birthday is on the : 14
birthday_func('July', 14)
My birthday is on the month of : July My birthday is on the : 14
birthday_func('July', '14')
My birthday is on the month of : July My birthday is on the : 14
birthday_func(7, '14')
My birthday is on the month of : 7 My birthday is on the : 14
def birthday_func(month, date):
assert month == str
print('My birthday is on the month of : '+ str(month))
print('My birthday is on the : ' + str(date))
birthday_func(7, '14')
--------------------------------------------------------------------------- AssertionError Traceback (most recent call last) <ipython-input-71-4ddaebe8be08> in <module> ----> 1 birthday_func(7, '14') <ipython-input-70-3b4dd0ccc843> in birthday_func(month, date) 1 def birthday_func(month, date): ----> 2 assert month == str 3 print('My birthday is on the month of : '+ str(month)) 4 print('My birthday is on the : ' + str(date)) 5 AssertionError:
def first_negative(values):
for v in values:
if v < 0:
return v
print(first_negative([5, 6,-1, 9 , 10]))
print(first_negative([]))
-1 None
def first_negative(values):
assert values != []
for v in values:
if v < 0:
return v
first_negative([5, 6,-1, 9 , 10])
first_negative([])
--------------------------------------------------------------------------- AssertionError Traceback (most recent call last) <ipython-input-77-c6bb682b4d5f> in <module> 5 return v 6 first_negative([5, 6,-1, 9 , 10]) ----> 7 first_negative([]) <ipython-input-77-c6bb682b4d5f> in first_negative(values) 1 def first_negative(values): ----> 2 assert values != [] 3 for v in values: 4 if v < 0: 5 return v AssertionError:
mylist = []
def first_negative(values):
for v in values:
if v >= 0:
print('I am in this if statement block')
continue
else:
mylist.append(v)
break
if len(mylist) == 1 :
return mylist
else:
return'There are no negatives'
first_negative([1,2,3,4])
I am in this if statement block I am in this if statement block I am in this if statement block I am in this if statement block
'There are no negatives'
mylist
[-5]
def func_returns():
print('hello')
print('hello')
print('hello')
print('hello')
func_returns()
hello hello hello hello
def func_returns(a):
if(a <= 5):
return('hello')
if(a >= 10):
return('bye')
func_returns()
b = 10
def math_ploy(x1):
y = x1 + b
print(y)
return y
print(math_ploy(5))
print(y)
15 15
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-115-f115e8ead91e> in <module> 6 7 print(math_ploy(5)) ----> 8 print(y) NameError: name 'y' is not defined
var = 5
var2 =4
def func_type1():
return 'hello'
def func_type2(var):
print(var)
def func_type3(cat = var, dog = var2):
print(cat -1)
print(dog -1)
func_type1()
'hello'
func_type2(5)
5
func_type3(cat=10, dog = 6)
9 5
def a():
return 5
def b(y):
print('this is my nested function')
y = a()
print(y)
b(y)
5 this is my nested function
import math
print('pi is ', math.pi)
pi is 3.141592653589793
math.cos(math.pi)
-1.0
from math import cos, pi
print(cos(pi))
-1.0
math.cos(math.pi)
-1.0
sin()
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-8-25560f9ce61b> in <module> ----> 1 sin() NameError: name 'sin' is not defined
import math as m
print(m.cos(m.pi))
-1.0
from math import cos, pi
sin(pi)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-9-1de0726db8ae> in <module> 1 from math import cos, pi 2 ----> 3 sin(pi) NameError: name 'sin' is not defined
sin(pi)
1.2246467991473532e-16
import numpy as np
a = np.array([1,2,3,4,5])
print(a)
type(a)
[1 2 3 4 5]
numpy.ndarray
a = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])
type(a)
numpy.ndarray
#np.arange(start, stop, step)
np.arange(1, 11, 1)
array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
#np.linspace(start, stop, n_elements)
start = 0
stop = 100
n_elements = 201
x = np.linspace(start, stop, n_elements)
print(x)
len(x)
[ 0. 0.5 1. 1.5 2. 2.5 3. 3.5 4. 4.5 5. 5.5 6. 6.5 7. 7.5 8. 8.5 9. 9.5 10. 10.5 11. 11.5 12. 12.5 13. 13.5 14. 14.5 15. 15.5 16. 16.5 17. 17.5 18. 18.5 19. 19.5 20. 20.5 21. 21.5 22. 22.5 23. 23.5 24. 24.5 25. 25.5 26. 26.5 27. 27.5 28. 28.5 29. 29.5 30. 30.5 31. 31.5 32. 32.5 33. 33.5 34. 34.5 35. 35.5 36. 36.5 37. 37.5 38. 38.5 39. 39.5 40. 40.5 41. 41.5 42. 42.5 43. 43.5 44. 44.5 45. 45.5 46. 46.5 47. 47.5 48. 48.5 49. 49.5 50. 50.5 51. 51.5 52. 52.5 53. 53.5 54. 54.5 55. 55.5 56. 56.5 57. 57.5 58. 58.5 59. 59.5 60. 60.5 61. 61.5 62. 62.5 63. 63.5 64. 64.5 65. 65.5 66. 66.5 67. 67.5 68. 68.5 69. 69.5 70. 70.5 71. 71.5 72. 72.5 73. 73.5 74. 74.5 75. 75.5 76. 76.5 77. 77.5 78. 78.5 79. 79.5 80. 80.5 81. 81.5 82. 82.5 83. 83.5 84. 84.5 85. 85.5 86. 86.5 87. 87.5 88. 88.5 89. 89.5 90. 90.5 91. 91.5 92. 92.5 93. 93.5 94. 94.5 95. 95.5 96. 96.5 97. 97.5 98. 98.5 99. 99.5 100. ]
201
x_5 = np.where(x %5 == 0)
print(x_5)
type(x_5)
#will return the indeces where in the x array it is divisible by 5
(array([ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]),)
tuple
x[x_5]
array([ 0., 5., 10., 15., 20., 25., 30., 35., 40., 45., 50., 55., 60., 65., 70., 75., 80., 85., 90., 95., 100.])
start =0
end = 100
n_elem = 501
x = np.linspace(start, end, n_elem)
print('x', x)
y = (.1*x)**2 - (5*x) + 3
print('y', y)
np.savetxt('my_text_file.txt', np.transpose([x,y]))
x [ 0. 0.2 0.4 0.6 0.8 1. 1.2 1.4 1.6 1.8 2. 2.2 2.4 2.6 2.8 3. 3.2 3.4 3.6 3.8 4. 4.2 4.4 4.6 4.8 5. 5.2 5.4 5.6 5.8 6. 6.2 6.4 6.6 6.8 7. 7.2 7.4 7.6 7.8 8. 8.2 8.4 8.6 8.8 9. 9.2 9.4 9.6 9.8 10. 10.2 10.4 10.6 10.8 11. 11.2 11.4 11.6 11.8 12. 12.2 12.4 12.6 12.8 13. 13.2 13.4 13.6 13.8 14. 14.2 14.4 14.6 14.8 15. 15.2 15.4 15.6 15.8 16. 16.2 16.4 16.6 16.8 17. 17.2 17.4 17.6 17.8 18. 18.2 18.4 18.6 18.8 19. 19.2 19.4 19.6 19.8 20. 20.2 20.4 20.6 20.8 21. 21.2 21.4 21.6 21.8 22. 22.2 22.4 22.6 22.8 23. 23.2 23.4 23.6 23.8 24. 24.2 24.4 24.6 24.8 25. 25.2 25.4 25.6 25.8 26. 26.2 26.4 26.6 26.8 27. 27.2 27.4 27.6 27.8 28. 28.2 28.4 28.6 28.8 29. 29.2 29.4 29.6 29.8 30. 30.2 30.4 30.6 30.8 31. 31.2 31.4 31.6 31.8 32. 32.2 32.4 32.6 32.8 33. 33.2 33.4 33.6 33.8 34. 34.2 34.4 34.6 34.8 35. 35.2 35.4 35.6 35.8 36. 36.2 36.4 36.6 36.8 37. 37.2 37.4 37.6 37.8 38. 38.2 38.4 38.6 38.8 39. 39.2 39.4 39.6 39.8 40. 40.2 40.4 40.6 40.8 41. 41.2 41.4 41.6 41.8 42. 42.2 42.4 42.6 42.8 43. 43.2 43.4 43.6 43.8 44. 44.2 44.4 44.6 44.8 45. 45.2 45.4 45.6 45.8 46. 46.2 46.4 46.6 46.8 47. 47.2 47.4 47.6 47.8 48. 48.2 48.4 48.6 48.8 49. 49.2 49.4 49.6 49.8 50. 50.2 50.4 50.6 50.8 51. 51.2 51.4 51.6 51.8 52. 52.2 52.4 52.6 52.8 53. 53.2 53.4 53.6 53.8 54. 54.2 54.4 54.6 54.8 55. 55.2 55.4 55.6 55.8 56. 56.2 56.4 56.6 56.8 57. 57.2 57.4 57.6 57.8 58. 58.2 58.4 58.6 58.8 59. 59.2 59.4 59.6 59.8 60. 60.2 60.4 60.6 60.8 61. 61.2 61.4 61.6 61.8 62. 62.2 62.4 62.6 62.8 63. 63.2 63.4 63.6 63.8 64. 64.2 64.4 64.6 64.8 65. 65.2 65.4 65.6 65.8 66. 66.2 66.4 66.6 66.8 67. 67.2 67.4 67.6 67.8 68. 68.2 68.4 68.6 68.8 69. 69.2 69.4 69.6 69.8 70. 70.2 70.4 70.6 70.8 71. 71.2 71.4 71.6 71.8 72. 72.2 72.4 72.6 72.8 73. 73.2 73.4 73.6 73.8 74. 74.2 74.4 74.6 74.8 75. 75.2 75.4 75.6 75.8 76. 76.2 76.4 76.6 76.8 77. 77.2 77.4 77.6 77.8 78. 78.2 78.4 78.6 78.8 79. 79.2 79.4 79.6 79.8 80. 80.2 80.4 80.6 80.8 81. 81.2 81.4 81.6 81.8 82. 82.2 82.4 82.6 82.8 83. 83.2 83.4 83.6 83.8 84. 84.2 84.4 84.6 84.8 85. 85.2 85.4 85.6 85.8 86. 86.2 86.4 86.6 86.8 87. 87.2 87.4 87.6 87.8 88. 88.2 88.4 88.6 88.8 89. 89.2 89.4 89.6 89.8 90. 90.2 90.4 90.6 90.8 91. 91.2 91.4 91.6 91.8 92. 92.2 92.4 92.6 92.8 93. 93.2 93.4 93.6 93.8 94. 94.2 94.4 94.6 94.8 95. 95.2 95.4 95.6 95.8 96. 96.2 96.4 96.6 96.8 97. 97.2 97.4 97.6 97.8 98. 98.2 98.4 98.6 98.8 99. 99.2 99.4 99.6 99.8 100. ] y [ 3.000000e+00 2.000400e+00 1.001600e+00 3.600000e-03 -9.936000e-01 -1.990000e+00 -2.985600e+00 -3.980400e+00 -4.974400e+00 -5.967600e+00 -6.960000e+00 -7.951600e+00 -8.942400e+00 -9.932400e+00 -1.092160e+01 -1.191000e+01 -1.289760e+01 -1.388440e+01 -1.487040e+01 -1.585560e+01 -1.684000e+01 -1.782360e+01 -1.880640e+01 -1.978840e+01 -2.076960e+01 -2.175000e+01 -2.272960e+01 -2.370840e+01 -2.468640e+01 -2.566360e+01 -2.664000e+01 -2.761560e+01 -2.859040e+01 -2.956440e+01 -3.053760e+01 -3.151000e+01 -3.248160e+01 -3.345240e+01 -3.442240e+01 -3.539160e+01 -3.636000e+01 -3.732760e+01 -3.829440e+01 -3.926040e+01 -4.022560e+01 -4.119000e+01 -4.215360e+01 -4.311640e+01 -4.407840e+01 -4.503960e+01 -4.600000e+01 -4.695960e+01 -4.791840e+01 -4.887640e+01 -4.983360e+01 -5.079000e+01 -5.174560e+01 -5.270040e+01 -5.365440e+01 -5.460760e+01 -5.556000e+01 -5.651160e+01 -5.746240e+01 -5.841240e+01 -5.936160e+01 -6.031000e+01 -6.125760e+01 -6.220440e+01 -6.315040e+01 -6.409560e+01 -6.504000e+01 -6.598360e+01 -6.692640e+01 -6.786840e+01 -6.880960e+01 -6.975000e+01 -7.068960e+01 -7.162840e+01 -7.256640e+01 -7.350360e+01 -7.444000e+01 -7.537560e+01 -7.631040e+01 -7.724440e+01 -7.817760e+01 -7.911000e+01 -8.004160e+01 -8.097240e+01 -8.190240e+01 -8.283160e+01 -8.376000e+01 -8.468760e+01 -8.561440e+01 -8.654040e+01 -8.746560e+01 -8.839000e+01 -8.931360e+01 -9.023640e+01 -9.115840e+01 -9.207960e+01 -9.300000e+01 -9.391960e+01 -9.483840e+01 -9.575640e+01 -9.667360e+01 -9.759000e+01 -9.850560e+01 -9.942040e+01 -1.003344e+02 -1.012476e+02 -1.021600e+02 -1.030716e+02 -1.039824e+02 -1.048924e+02 -1.058016e+02 -1.067100e+02 -1.076176e+02 -1.085244e+02 -1.094304e+02 -1.103356e+02 -1.112400e+02 -1.121436e+02 -1.130464e+02 -1.139484e+02 -1.148496e+02 -1.157500e+02 -1.166496e+02 -1.175484e+02 -1.184464e+02 -1.193436e+02 -1.202400e+02 -1.211356e+02 -1.220304e+02 -1.229244e+02 -1.238176e+02 -1.247100e+02 -1.256016e+02 -1.264924e+02 -1.273824e+02 -1.282716e+02 -1.291600e+02 -1.300476e+02 -1.309344e+02 -1.318204e+02 -1.327056e+02 -1.335900e+02 -1.344736e+02 -1.353564e+02 -1.362384e+02 -1.371196e+02 -1.380000e+02 -1.388796e+02 -1.397584e+02 -1.406364e+02 -1.415136e+02 -1.423900e+02 -1.432656e+02 -1.441404e+02 -1.450144e+02 -1.458876e+02 -1.467600e+02 -1.476316e+02 -1.485024e+02 -1.493724e+02 -1.502416e+02 -1.511100e+02 -1.519776e+02 -1.528444e+02 -1.537104e+02 -1.545756e+02 -1.554400e+02 -1.563036e+02 -1.571664e+02 -1.580284e+02 -1.588896e+02 -1.597500e+02 -1.606096e+02 -1.614684e+02 -1.623264e+02 -1.631836e+02 -1.640400e+02 -1.648956e+02 -1.657504e+02 -1.666044e+02 -1.674576e+02 -1.683100e+02 -1.691616e+02 -1.700124e+02 -1.708624e+02 -1.717116e+02 -1.725600e+02 -1.734076e+02 -1.742544e+02 -1.751004e+02 -1.759456e+02 -1.767900e+02 -1.776336e+02 -1.784764e+02 -1.793184e+02 -1.801596e+02 -1.810000e+02 -1.818396e+02 -1.826784e+02 -1.835164e+02 -1.843536e+02 -1.851900e+02 -1.860256e+02 -1.868604e+02 -1.876944e+02 -1.885276e+02 -1.893600e+02 -1.901916e+02 -1.910224e+02 -1.918524e+02 -1.926816e+02 -1.935100e+02 -1.943376e+02 -1.951644e+02 -1.959904e+02 -1.968156e+02 -1.976400e+02 -1.984636e+02 -1.992864e+02 -2.001084e+02 -2.009296e+02 -2.017500e+02 -2.025696e+02 -2.033884e+02 -2.042064e+02 -2.050236e+02 -2.058400e+02 -2.066556e+02 -2.074704e+02 -2.082844e+02 -2.090976e+02 -2.099100e+02 -2.107216e+02 -2.115324e+02 -2.123424e+02 -2.131516e+02 -2.139600e+02 -2.147676e+02 -2.155744e+02 -2.163804e+02 -2.171856e+02 -2.179900e+02 -2.187936e+02 -2.195964e+02 -2.203984e+02 -2.211996e+02 -2.220000e+02 -2.227996e+02 -2.235984e+02 -2.243964e+02 -2.251936e+02 -2.259900e+02 -2.267856e+02 -2.275804e+02 -2.283744e+02 -2.291676e+02 -2.299600e+02 -2.307516e+02 -2.315424e+02 -2.323324e+02 -2.331216e+02 -2.339100e+02 -2.346976e+02 -2.354844e+02 -2.362704e+02 -2.370556e+02 -2.378400e+02 -2.386236e+02 -2.394064e+02 -2.401884e+02 -2.409696e+02 -2.417500e+02 -2.425296e+02 -2.433084e+02 -2.440864e+02 -2.448636e+02 -2.456400e+02 -2.464156e+02 -2.471904e+02 -2.479644e+02 -2.487376e+02 -2.495100e+02 -2.502816e+02 -2.510524e+02 -2.518224e+02 -2.525916e+02 -2.533600e+02 -2.541276e+02 -2.548944e+02 -2.556604e+02 -2.564256e+02 -2.571900e+02 -2.579536e+02 -2.587164e+02 -2.594784e+02 -2.602396e+02 -2.610000e+02 -2.617596e+02 -2.625184e+02 -2.632764e+02 -2.640336e+02 -2.647900e+02 -2.655456e+02 -2.663004e+02 -2.670544e+02 -2.678076e+02 -2.685600e+02 -2.693116e+02 -2.700624e+02 -2.708124e+02 -2.715616e+02 -2.723100e+02 -2.730576e+02 -2.738044e+02 -2.745504e+02 -2.752956e+02 -2.760400e+02 -2.767836e+02 -2.775264e+02 -2.782684e+02 -2.790096e+02 -2.797500e+02 -2.804896e+02 -2.812284e+02 -2.819664e+02 -2.827036e+02 -2.834400e+02 -2.841756e+02 -2.849104e+02 -2.856444e+02 -2.863776e+02 -2.871100e+02 -2.878416e+02 -2.885724e+02 -2.893024e+02 -2.900316e+02 -2.907600e+02 -2.914876e+02 -2.922144e+02 -2.929404e+02 -2.936656e+02 -2.943900e+02 -2.951136e+02 -2.958364e+02 -2.965584e+02 -2.972796e+02 -2.980000e+02 -2.987196e+02 -2.994384e+02 -3.001564e+02 -3.008736e+02 -3.015900e+02 -3.023056e+02 -3.030204e+02 -3.037344e+02 -3.044476e+02 -3.051600e+02 -3.058716e+02 -3.065824e+02 -3.072924e+02 -3.080016e+02 -3.087100e+02 -3.094176e+02 -3.101244e+02 -3.108304e+02 -3.115356e+02 -3.122400e+02 -3.129436e+02 -3.136464e+02 -3.143484e+02 -3.150496e+02 -3.157500e+02 -3.164496e+02 -3.171484e+02 -3.178464e+02 -3.185436e+02 -3.192400e+02 -3.199356e+02 -3.206304e+02 -3.213244e+02 -3.220176e+02 -3.227100e+02 -3.234016e+02 -3.240924e+02 -3.247824e+02 -3.254716e+02 -3.261600e+02 -3.268476e+02 -3.275344e+02 -3.282204e+02 -3.289056e+02 -3.295900e+02 -3.302736e+02 -3.309564e+02 -3.316384e+02 -3.323196e+02 -3.330000e+02 -3.336796e+02 -3.343584e+02 -3.350364e+02 -3.357136e+02 -3.363900e+02 -3.370656e+02 -3.377404e+02 -3.384144e+02 -3.390876e+02 -3.397600e+02 -3.404316e+02 -3.411024e+02 -3.417724e+02 -3.424416e+02 -3.431100e+02 -3.437776e+02 -3.444444e+02 -3.451104e+02 -3.457756e+02 -3.464400e+02 -3.471036e+02 -3.477664e+02 -3.484284e+02 -3.490896e+02 -3.497500e+02 -3.504096e+02 -3.510684e+02 -3.517264e+02 -3.523836e+02 -3.530400e+02 -3.536956e+02 -3.543504e+02 -3.550044e+02 -3.556576e+02 -3.563100e+02 -3.569616e+02 -3.576124e+02 -3.582624e+02 -3.589116e+02 -3.595600e+02 -3.602076e+02 -3.608544e+02 -3.615004e+02 -3.621456e+02 -3.627900e+02 -3.634336e+02 -3.640764e+02 -3.647184e+02 -3.653596e+02 -3.660000e+02 -3.666396e+02 -3.672784e+02 -3.679164e+02 -3.685536e+02 -3.691900e+02 -3.698256e+02 -3.704604e+02 -3.710944e+02 -3.717276e+02 -3.723600e+02 -3.729916e+02 -3.736224e+02 -3.742524e+02 -3.748816e+02 -3.755100e+02 -3.761376e+02 -3.767644e+02 -3.773904e+02 -3.780156e+02 -3.786400e+02 -3.792636e+02 -3.798864e+02 -3.805084e+02 -3.811296e+02 -3.817500e+02 -3.823696e+02 -3.829884e+02 -3.836064e+02 -3.842236e+02 -3.848400e+02 -3.854556e+02 -3.860704e+02 -3.866844e+02 -3.872976e+02 -3.879100e+02 -3.885216e+02 -3.891324e+02 -3.897424e+02 -3.903516e+02 -3.909600e+02 -3.915676e+02 -3.921744e+02 -3.927804e+02 -3.933856e+02 -3.939900e+02 -3.945936e+02 -3.951964e+02 -3.957984e+02 -3.963996e+02 -3.970000e+02]
pwd
'/Users/suarezc/Desktop/Bootcamp_2021/Untitled Folder'
data = np.loadtxt('../my_text_file.txt')
#data = np.loadtxt('..\my_text_file.txt') # For windows path
print(data)
[[ 0.000000e+00 3.000000e+00] [ 2.000000e-01 2.000400e+00] [ 4.000000e-01 1.001600e+00] ... [ 9.960000e+01 -3.957984e+02] [ 9.980000e+01 -3.963996e+02] [ 1.000000e+02 -3.970000e+02]]
data[0]
array([0., 3.])
#All rows, first column
data[:,0]
array([ 0. , 0.2, 0.4, 0.6, 0.8, 1. , 1.2, 1.4, 1.6, 1.8, 2. , 2.2, 2.4, 2.6, 2.8, 3. , 3.2, 3.4, 3.6, 3.8, 4. , 4.2, 4.4, 4.6, 4.8, 5. , 5.2, 5.4, 5.6, 5.8, 6. , 6.2, 6.4, 6.6, 6.8, 7. , 7.2, 7.4, 7.6, 7.8, 8. , 8.2, 8.4, 8.6, 8.8, 9. , 9.2, 9.4, 9.6, 9.8, 10. , 10.2, 10.4, 10.6, 10.8, 11. , 11.2, 11.4, 11.6, 11.8, 12. , 12.2, 12.4, 12.6, 12.8, 13. , 13.2, 13.4, 13.6, 13.8, 14. , 14.2, 14.4, 14.6, 14.8, 15. , 15.2, 15.4, 15.6, 15.8, 16. , 16.2, 16.4, 16.6, 16.8, 17. , 17.2, 17.4, 17.6, 17.8, 18. , 18.2, 18.4, 18.6, 18.8, 19. , 19.2, 19.4, 19.6, 19.8, 20. , 20.2, 20.4, 20.6, 20.8, 21. , 21.2, 21.4, 21.6, 21.8, 22. , 22.2, 22.4, 22.6, 22.8, 23. , 23.2, 23.4, 23.6, 23.8, 24. , 24.2, 24.4, 24.6, 24.8, 25. , 25.2, 25.4, 25.6, 25.8, 26. , 26.2, 26.4, 26.6, 26.8, 27. , 27.2, 27.4, 27.6, 27.8, 28. , 28.2, 28.4, 28.6, 28.8, 29. , 29.2, 29.4, 29.6, 29.8, 30. , 30.2, 30.4, 30.6, 30.8, 31. , 31.2, 31.4, 31.6, 31.8, 32. , 32.2, 32.4, 32.6, 32.8, 33. , 33.2, 33.4, 33.6, 33.8, 34. , 34.2, 34.4, 34.6, 34.8, 35. , 35.2, 35.4, 35.6, 35.8, 36. , 36.2, 36.4, 36.6, 36.8, 37. , 37.2, 37.4, 37.6, 37.8, 38. , 38.2, 38.4, 38.6, 38.8, 39. , 39.2, 39.4, 39.6, 39.8, 40. , 40.2, 40.4, 40.6, 40.8, 41. , 41.2, 41.4, 41.6, 41.8, 42. , 42.2, 42.4, 42.6, 42.8, 43. , 43.2, 43.4, 43.6, 43.8, 44. , 44.2, 44.4, 44.6, 44.8, 45. , 45.2, 45.4, 45.6, 45.8, 46. , 46.2, 46.4, 46.6, 46.8, 47. , 47.2, 47.4, 47.6, 47.8, 48. , 48.2, 48.4, 48.6, 48.8, 49. , 49.2, 49.4, 49.6, 49.8, 50. , 50.2, 50.4, 50.6, 50.8, 51. , 51.2, 51.4, 51.6, 51.8, 52. , 52.2, 52.4, 52.6, 52.8, 53. , 53.2, 53.4, 53.6, 53.8, 54. , 54.2, 54.4, 54.6, 54.8, 55. , 55.2, 55.4, 55.6, 55.8, 56. , 56.2, 56.4, 56.6, 56.8, 57. , 57.2, 57.4, 57.6, 57.8, 58. , 58.2, 58.4, 58.6, 58.8, 59. , 59.2, 59.4, 59.6, 59.8, 60. , 60.2, 60.4, 60.6, 60.8, 61. , 61.2, 61.4, 61.6, 61.8, 62. , 62.2, 62.4, 62.6, 62.8, 63. , 63.2, 63.4, 63.6, 63.8, 64. , 64.2, 64.4, 64.6, 64.8, 65. , 65.2, 65.4, 65.6, 65.8, 66. , 66.2, 66.4, 66.6, 66.8, 67. , 67.2, 67.4, 67.6, 67.8, 68. , 68.2, 68.4, 68.6, 68.8, 69. , 69.2, 69.4, 69.6, 69.8, 70. , 70.2, 70.4, 70.6, 70.8, 71. , 71.2, 71.4, 71.6, 71.8, 72. , 72.2, 72.4, 72.6, 72.8, 73. , 73.2, 73.4, 73.6, 73.8, 74. , 74.2, 74.4, 74.6, 74.8, 75. , 75.2, 75.4, 75.6, 75.8, 76. , 76.2, 76.4, 76.6, 76.8, 77. , 77.2, 77.4, 77.6, 77.8, 78. , 78.2, 78.4, 78.6, 78.8, 79. , 79.2, 79.4, 79.6, 79.8, 80. , 80.2, 80.4, 80.6, 80.8, 81. , 81.2, 81.4, 81.6, 81.8, 82. , 82.2, 82.4, 82.6, 82.8, 83. , 83.2, 83.4, 83.6, 83.8, 84. , 84.2, 84.4, 84.6, 84.8, 85. , 85.2, 85.4, 85.6, 85.8, 86. , 86.2, 86.4, 86.6, 86.8, 87. , 87.2, 87.4, 87.6, 87.8, 88. , 88.2, 88.4, 88.6, 88.8, 89. , 89.2, 89.4, 89.6, 89.8, 90. , 90.2, 90.4, 90.6, 90.8, 91. , 91.2, 91.4, 91.6, 91.8, 92. , 92.2, 92.4, 92.6, 92.8, 93. , 93.2, 93.4, 93.6, 93.8, 94. , 94.2, 94.4, 94.6, 94.8, 95. , 95.2, 95.4, 95.6, 95.8, 96. , 96.2, 96.4, 96.6, 96.8, 97. , 97.2, 97.4, 97.6, 97.8, 98. , 98.2, 98.4, 98.6, 98.8, 99. , 99.2, 99.4, 99.6, 99.8, 100. ])
#All rows, second column
data[:,1]
array([ 3.000000e+00, 2.000400e+00, 1.001600e+00, 3.600000e-03, -9.936000e-01, -1.990000e+00, -2.985600e+00, -3.980400e+00, -4.974400e+00, -5.967600e+00, -6.960000e+00, -7.951600e+00, -8.942400e+00, -9.932400e+00, -1.092160e+01, -1.191000e+01, -1.289760e+01, -1.388440e+01, -1.487040e+01, -1.585560e+01, -1.684000e+01, -1.782360e+01, -1.880640e+01, -1.978840e+01, -2.076960e+01, -2.175000e+01, -2.272960e+01, -2.370840e+01, -2.468640e+01, -2.566360e+01, -2.664000e+01, -2.761560e+01, -2.859040e+01, -2.956440e+01, -3.053760e+01, -3.151000e+01, -3.248160e+01, -3.345240e+01, -3.442240e+01, -3.539160e+01, -3.636000e+01, -3.732760e+01, -3.829440e+01, -3.926040e+01, -4.022560e+01, -4.119000e+01, -4.215360e+01, -4.311640e+01, -4.407840e+01, -4.503960e+01, -4.600000e+01, -4.695960e+01, -4.791840e+01, -4.887640e+01, -4.983360e+01, -5.079000e+01, -5.174560e+01, -5.270040e+01, -5.365440e+01, -5.460760e+01, -5.556000e+01, -5.651160e+01, -5.746240e+01, -5.841240e+01, -5.936160e+01, -6.031000e+01, -6.125760e+01, -6.220440e+01, -6.315040e+01, -6.409560e+01, -6.504000e+01, -6.598360e+01, -6.692640e+01, -6.786840e+01, -6.880960e+01, -6.975000e+01, -7.068960e+01, -7.162840e+01, -7.256640e+01, -7.350360e+01, -7.444000e+01, -7.537560e+01, -7.631040e+01, -7.724440e+01, -7.817760e+01, -7.911000e+01, -8.004160e+01, -8.097240e+01, -8.190240e+01, -8.283160e+01, -8.376000e+01, -8.468760e+01, -8.561440e+01, -8.654040e+01, -8.746560e+01, -8.839000e+01, -8.931360e+01, -9.023640e+01, -9.115840e+01, -9.207960e+01, -9.300000e+01, -9.391960e+01, -9.483840e+01, -9.575640e+01, -9.667360e+01, -9.759000e+01, -9.850560e+01, -9.942040e+01, -1.003344e+02, -1.012476e+02, -1.021600e+02, -1.030716e+02, -1.039824e+02, -1.048924e+02, -1.058016e+02, -1.067100e+02, -1.076176e+02, -1.085244e+02, -1.094304e+02, -1.103356e+02, -1.112400e+02, -1.121436e+02, -1.130464e+02, -1.139484e+02, -1.148496e+02, -1.157500e+02, -1.166496e+02, -1.175484e+02, -1.184464e+02, -1.193436e+02, -1.202400e+02, -1.211356e+02, -1.220304e+02, -1.229244e+02, -1.238176e+02, -1.247100e+02, -1.256016e+02, -1.264924e+02, -1.273824e+02, -1.282716e+02, -1.291600e+02, -1.300476e+02, -1.309344e+02, -1.318204e+02, -1.327056e+02, -1.335900e+02, -1.344736e+02, -1.353564e+02, -1.362384e+02, -1.371196e+02, -1.380000e+02, -1.388796e+02, -1.397584e+02, -1.406364e+02, -1.415136e+02, -1.423900e+02, -1.432656e+02, -1.441404e+02, -1.450144e+02, -1.458876e+02, -1.467600e+02, -1.476316e+02, -1.485024e+02, -1.493724e+02, -1.502416e+02, -1.511100e+02, -1.519776e+02, -1.528444e+02, -1.537104e+02, -1.545756e+02, -1.554400e+02, -1.563036e+02, -1.571664e+02, -1.580284e+02, -1.588896e+02, -1.597500e+02, -1.606096e+02, -1.614684e+02, -1.623264e+02, -1.631836e+02, -1.640400e+02, -1.648956e+02, -1.657504e+02, -1.666044e+02, -1.674576e+02, -1.683100e+02, -1.691616e+02, -1.700124e+02, -1.708624e+02, -1.717116e+02, -1.725600e+02, -1.734076e+02, -1.742544e+02, -1.751004e+02, -1.759456e+02, -1.767900e+02, -1.776336e+02, -1.784764e+02, -1.793184e+02, -1.801596e+02, -1.810000e+02, -1.818396e+02, -1.826784e+02, -1.835164e+02, -1.843536e+02, -1.851900e+02, -1.860256e+02, -1.868604e+02, -1.876944e+02, -1.885276e+02, -1.893600e+02, -1.901916e+02, -1.910224e+02, -1.918524e+02, -1.926816e+02, -1.935100e+02, -1.943376e+02, -1.951644e+02, -1.959904e+02, -1.968156e+02, -1.976400e+02, -1.984636e+02, -1.992864e+02, -2.001084e+02, -2.009296e+02, -2.017500e+02, -2.025696e+02, -2.033884e+02, -2.042064e+02, -2.050236e+02, -2.058400e+02, -2.066556e+02, -2.074704e+02, -2.082844e+02, -2.090976e+02, -2.099100e+02, -2.107216e+02, -2.115324e+02, -2.123424e+02, -2.131516e+02, -2.139600e+02, -2.147676e+02, -2.155744e+02, -2.163804e+02, -2.171856e+02, -2.179900e+02, -2.187936e+02, -2.195964e+02, -2.203984e+02, -2.211996e+02, -2.220000e+02, -2.227996e+02, -2.235984e+02, -2.243964e+02, -2.251936e+02, -2.259900e+02, -2.267856e+02, -2.275804e+02, -2.283744e+02, -2.291676e+02, -2.299600e+02, -2.307516e+02, -2.315424e+02, -2.323324e+02, -2.331216e+02, -2.339100e+02, -2.346976e+02, -2.354844e+02, -2.362704e+02, -2.370556e+02, -2.378400e+02, -2.386236e+02, -2.394064e+02, -2.401884e+02, -2.409696e+02, -2.417500e+02, -2.425296e+02, -2.433084e+02, -2.440864e+02, -2.448636e+02, -2.456400e+02, -2.464156e+02, -2.471904e+02, -2.479644e+02, -2.487376e+02, -2.495100e+02, -2.502816e+02, -2.510524e+02, -2.518224e+02, -2.525916e+02, -2.533600e+02, -2.541276e+02, -2.548944e+02, -2.556604e+02, -2.564256e+02, -2.571900e+02, -2.579536e+02, -2.587164e+02, -2.594784e+02, -2.602396e+02, -2.610000e+02, -2.617596e+02, -2.625184e+02, -2.632764e+02, -2.640336e+02, -2.647900e+02, -2.655456e+02, -2.663004e+02, -2.670544e+02, -2.678076e+02, -2.685600e+02, -2.693116e+02, -2.700624e+02, -2.708124e+02, -2.715616e+02, -2.723100e+02, -2.730576e+02, -2.738044e+02, -2.745504e+02, -2.752956e+02, -2.760400e+02, -2.767836e+02, -2.775264e+02, -2.782684e+02, -2.790096e+02, -2.797500e+02, -2.804896e+02, -2.812284e+02, -2.819664e+02, -2.827036e+02, -2.834400e+02, -2.841756e+02, -2.849104e+02, -2.856444e+02, -2.863776e+02, -2.871100e+02, -2.878416e+02, -2.885724e+02, -2.893024e+02, -2.900316e+02, -2.907600e+02, -2.914876e+02, -2.922144e+02, -2.929404e+02, -2.936656e+02, -2.943900e+02, -2.951136e+02, -2.958364e+02, -2.965584e+02, -2.972796e+02, -2.980000e+02, -2.987196e+02, -2.994384e+02, -3.001564e+02, -3.008736e+02, -3.015900e+02, -3.023056e+02, -3.030204e+02, -3.037344e+02, -3.044476e+02, -3.051600e+02, -3.058716e+02, -3.065824e+02, -3.072924e+02, -3.080016e+02, -3.087100e+02, -3.094176e+02, -3.101244e+02, -3.108304e+02, -3.115356e+02, -3.122400e+02, -3.129436e+02, -3.136464e+02, -3.143484e+02, -3.150496e+02, -3.157500e+02, -3.164496e+02, -3.171484e+02, -3.178464e+02, -3.185436e+02, -3.192400e+02, -3.199356e+02, -3.206304e+02, -3.213244e+02, -3.220176e+02, -3.227100e+02, -3.234016e+02, -3.240924e+02, -3.247824e+02, -3.254716e+02, -3.261600e+02, -3.268476e+02, -3.275344e+02, -3.282204e+02, -3.289056e+02, -3.295900e+02, -3.302736e+02, -3.309564e+02, -3.316384e+02, -3.323196e+02, -3.330000e+02, -3.336796e+02, -3.343584e+02, -3.350364e+02, -3.357136e+02, -3.363900e+02, -3.370656e+02, -3.377404e+02, -3.384144e+02, -3.390876e+02, -3.397600e+02, -3.404316e+02, -3.411024e+02, -3.417724e+02, -3.424416e+02, -3.431100e+02, -3.437776e+02, -3.444444e+02, -3.451104e+02, -3.457756e+02, -3.464400e+02, -3.471036e+02, -3.477664e+02, -3.484284e+02, -3.490896e+02, -3.497500e+02, -3.504096e+02, -3.510684e+02, -3.517264e+02, -3.523836e+02, -3.530400e+02, -3.536956e+02, -3.543504e+02, -3.550044e+02, -3.556576e+02, -3.563100e+02, -3.569616e+02, -3.576124e+02, -3.582624e+02, -3.589116e+02, -3.595600e+02, -3.602076e+02, -3.608544e+02, -3.615004e+02, -3.621456e+02, -3.627900e+02, -3.634336e+02, -3.640764e+02, -3.647184e+02, -3.653596e+02, -3.660000e+02, -3.666396e+02, -3.672784e+02, -3.679164e+02, -3.685536e+02, -3.691900e+02, -3.698256e+02, -3.704604e+02, -3.710944e+02, -3.717276e+02, -3.723600e+02, -3.729916e+02, -3.736224e+02, -3.742524e+02, -3.748816e+02, -3.755100e+02, -3.761376e+02, -3.767644e+02, -3.773904e+02, -3.780156e+02, -3.786400e+02, -3.792636e+02, -3.798864e+02, -3.805084e+02, -3.811296e+02, -3.817500e+02, -3.823696e+02, -3.829884e+02, -3.836064e+02, -3.842236e+02, -3.848400e+02, -3.854556e+02, -3.860704e+02, -3.866844e+02, -3.872976e+02, -3.879100e+02, -3.885216e+02, -3.891324e+02, -3.897424e+02, -3.903516e+02, -3.909600e+02, -3.915676e+02, -3.921744e+02, -3.927804e+02, -3.933856e+02, -3.939900e+02, -3.945936e+02, -3.951964e+02, -3.957984e+02, -3.963996e+02, -3.970000e+02])
a = np.empty(4)
a.fill(5.5)
a
array([5.5, 5.5, 5.5, 5.5])
np.arange(5)
array([0, 1, 2, 3, 4])
b = np.random.normal(10,3,5)
b
array([ 5.21504731, 9.33161611, 7.82804446, 13.43441166, 14.88559031])
mask = b > 9
mask
array([False, True, False, True, True])
b[mask]
array([ 9.33161611, 13.43441166, 14.88559031])
b[mask] = 0
b
array([5.21504731, 0. , 7.82804446, 0. , 0. ])
c = np.random.normal(10,3, (2,4))
c
array([[12.13497155, 11.88190856, 6.23317578, 12.41081666], [16.14427092, 10.70031063, 10.39910172, 9.10741824]])
c.shape
(2, 4)
c.sum()
89.01197405930381
c.sum(axis=0)
array([28.27924247, 22.58221919, 16.6322775 , 21.5182349 ])
c
array([[12.13497155, 11.88190856, 6.23317578, 12.41081666], [16.14427092, 10.70031063, 10.39910172, 9.10741824]])
c[0,:]
array([12.13497155, 11.88190856, 6.23317578, 12.41081666])
c[1,:]
array([16.14427092, 10.70031063, 10.39910172, 9.10741824])
c[:,0]
array([12.13497155, 16.14427092])
c.flatten()
array([12.13497155, 11.88190856, 6.23317578, 12.41081666, 16.14427092, 10.70031063, 10.39910172, 9.10741824])
np.array2string(np.array(['hello', 'lunch']))
"['hello' 'lunch']"
import pandas as pd
data = pd.read_csv('../Python/gapminder_data/data/gapminder_gdp_oceania.csv')
data.describe()
gdpPercap_1952 | gdpPercap_1957 | gdpPercap_1962 | gdpPercap_1967 | gdpPercap_1972 | gdpPercap_1977 | gdpPercap_1982 | gdpPercap_1987 | gdpPercap_1992 | gdpPercap_1997 | gdpPercap_2002 | gdpPercap_2007 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
count | 2.000000 | 2.000000 | 2.000000 | 2.000000 | 2.00000 | 2.000000 | 2.000000 | 2.000000 | 2.000000 | 2.000000 | 2.000000 | 2.000000 |
mean | 10298.085650 | 11598.522455 | 12696.452430 | 14495.021790 | 16417.33338 | 17283.957605 | 18554.709840 | 20448.040160 | 20894.045885 | 24024.175170 | 26938.778040 | 29810.188275 |
std | 365.560078 | 917.644806 | 677.727301 | 43.986086 | 525.09198 | 1485.263517 | 1304.328377 | 2037.668013 | 3578.979883 | 4205.533703 | 5301.853680 | 6540.991104 |
min | 10039.595640 | 10949.649590 | 12217.226860 | 14463.918930 | 16046.03728 | 16233.717700 | 17632.410400 | 19007.191290 | 18363.324940 | 21050.413770 | 23189.801350 | 25185.009110 |
25% | 10168.840645 | 11274.086022 | 12456.839645 | 14479.470360 | 16231.68533 | 16758.837652 | 18093.560120 | 19727.615725 | 19628.685412 | 22537.294470 | 25064.289695 | 27497.598692 |
50% | 10298.085650 | 11598.522455 | 12696.452430 | 14495.021790 | 16417.33338 | 17283.957605 | 18554.709840 | 20448.040160 | 20894.045885 | 24024.175170 | 26938.778040 | 29810.188275 |
75% | 10427.330655 | 11922.958888 | 12936.065215 | 14510.573220 | 16602.98143 | 17809.077558 | 19015.859560 | 21168.464595 | 22159.406358 | 25511.055870 | 28813.266385 | 32122.777858 |
max | 10556.575660 | 12247.395320 | 13175.678000 | 14526.124650 | 16788.62948 | 18334.197510 | 19477.009280 | 21888.889030 | 23424.766830 | 26997.936570 | 30687.754730 | 34435.367440 |
data
country | gdpPercap_1952 | gdpPercap_1957 | gdpPercap_1962 | gdpPercap_1967 | gdpPercap_1972 | gdpPercap_1977 | gdpPercap_1982 | gdpPercap_1987 | gdpPercap_1992 | gdpPercap_1997 | gdpPercap_2002 | gdpPercap_2007 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | Australia | 10039.59564 | 10949.64959 | 12217.22686 | 14526.12465 | 16788.62948 | 18334.19751 | 19477.00928 | 21888.88903 | 23424.76683 | 26997.93657 | 30687.75473 | 34435.36744 |
1 | New Zealand | 10556.57566 | 12247.39532 | 13175.67800 | 14463.91893 | 16046.03728 | 16233.71770 | 17632.41040 | 19007.19129 | 18363.32494 | 21050.41377 | 23189.80135 | 25185.00911 |
c
array([[12.13497155, 11.88190856, 6.23317578, 12.41081666], [16.14427092, 10.70031063, 10.39910172, 9.10741824]])
df_c = pd.DataFrame(c)
df_c.describe()
0 | 1 | 2 | 3 | |
---|---|---|---|---|
count | 2.000000 | 2.000000 | 2.000000 | 2.000000 |
mean | 14.139621 | 11.291110 | 8.316139 | 10.759117 |
std | 2.835003 | 0.835516 | 2.945754 | 2.335855 |
min | 12.134972 | 10.700311 | 6.233176 | 9.107418 |
25% | 13.137296 | 10.995710 | 7.274657 | 9.933268 |
50% | 14.139621 | 11.291110 | 8.316139 | 10.759117 |
75% | 15.141946 | 11.586509 | 9.357620 | 11.584967 |
max | 16.144271 | 11.881909 | 10.399102 | 12.410817 |