Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
##fibo
def fin(n):
result=[0,1]
a,b=0,1
i=1
while i<n:
a,b=b,a+b
result.append(b)
i+=1
return result
print(fin(5))
def fin(n):
result=[0,1]
a,b=0,1
i=0
while i<n-2:
a,b=b,a+b
result.append(b)
i+=1
return result
try:
n=int(input("enter a no"))
print(fin(n))
except :
#### Class
class User(object):
def __init__(self,fname,lname,email):
self.fname=fname
self.lname=lname
self.email=email
def get_details(self):
print("User's Name: {} {}".format (self.fname,self.lname))
print("Email: {}".format(self.email))
class User(object):
def __init__(self,fname,lname,email):
self.fname=fname
self.lname=lname
self.email=email
(C:\ProgramData\Anaconda3) C:\Users\win7\Desktop\arun>
class Dog():
def __init__(self, name, age):
self.name = name
self.age = age
def sit(self):
print(self.name.title() + " is now sitting.")
def roll_over(self):
print(self.name.title() + " rolled over!")
class BankAccount(object):
def __init__(self, initial_balance=0):
self.balance = initial_balance
def deposit(self, amount):
self.balance += amount
def withdraw(self, amount):
self.balance -= amount
def overdrawn(self):
return self.balance < 0
my_account = BankAccount(15)
my_account.withdraw(5)
print (my_account.balance)
# numpy
^
SyntaxError: invalid syntax
>>> matrix= np.array ([[1,2,3],[4,5,6]])
>>> matrix
array([[1, 2, 3],
[4, 5, 6]])
>>> matrix= np.array ([[1,2,3],[4,5,6],[6,7,8]])
>>> matrix
array([[1, 2, 3],
[4, 5, 6],
[6, 7, 8]])
>>> type(matrix)
<class 'numpy.ndarray'>
>>> matrix.dtype
dtype('int32')
>>>
>>> matrix2=np.array([[1,2,3],[4,5,6]],dtype=np.float64)
>>> matrix2
array([[ 1., 2., 3.],
[ 4., 5., 6.]])
>>> matrix2.dtype
dtype('float64')
>>> np.zeros((3,5),dtype='int32')
array([[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]])
>>> np.ones((3,5),dtype='int32')
array([[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1]])
>>>
(C:\ProgramData\Anaconda3) C:\Users\win7\Desktop\arun>jupyter notebook
http://localhost:8888/tree#
http://localhost:8888/notebooks/Untitled.ipynb?kernel_name=python3
import numpy as np
import time
import sys
size=1000
I1=range(size)
I2=range(size)
start=time.time()
final=[x+y for x,y in zip(I1,I2)]
print(time.time()-start)
size=1000
I1=range(size)
I2=range(size)
start=time.time()
final=[x+y for x,y in zip(I1,I2)]
print((time.time()-start)*1000)
1.0001659393310547
a1=np.arange(size)
a2=np.arange(size)
start=time.time()
final=a1+a2
print((time.time()-start)*1000)
73.00400733947754
print(sys.getsizeof(5)*len(I1))
14000
print(a1.itemsize*a1.size)
4000
----------------------------------------
import numpy as np
import matplotlib.pyplot as pit
import pandas as pd
from sklearn.datasets import load_boston
boston=load_boston()
boston.feature_names
features=pd.DataFrame(boston.data,columns=boston.feature_names)
target=pd.DataFrame(boston.target,columns=["Target"])
features.head(10)
Notes
------
Data Set Characteristics:
x=features["LSTAT"]
y=target
%matplotlib inline
plt.plot(x,y,'b.')
---------------------------------
>>> import os
>>> import sys
>>> os.path.dirname(sys.executable)
'C:\\Users\\HP\\AppData\\Local\\Programs\\Python\\Python36-32'