You are on page 1of 4

11/29/22, 10:32 AM 30 September 2022 sympy array - Jupyter Notebook

numpy module: numerical python


#find difference btw math and numpy module in action

help()

In [*]:

help()

Welcome to Python 3.9's help utility!

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at https://docs.python.org/3.9/tutorial/. (http
s://docs.python.org/3.9/tutorial/.)

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules. To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, symbols, or topics, type


"modules", "keywords", "symbols", or "topics". Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".

help>

In [4]:

#to imoport write import module name or import module name as your name
#eg: import numpy as n
#eg. from math import factorial

Input In [4]
eg: import numpy as n
^
SyntaxError: invalid syntax

In [6]:

import numpy
numpy.zeros(2) #answer has a dot 0. bcoz of the way it was written

Out[6]:

array([0., 0.])

localhost:8888/notebooks/30 September 2022 sympy array.ipynb 1/4


11/29/22, 10:32 AM 30 September 2022 sympy array - Jupyter Notebook

In [7]:

import numpy
numpy.ones(3)

Out[7]:

array([1., 1., 1.])

In [10]:

import numpy as n
n.ones(3)

Out[10]:

array([1., 1., 1.])

In [21]:

import numpy as n
n.zeros(3)

Out[21]:

array([0., 0., 0.])

In [1]:

import numpy as n
n.ones((3,3))

Out[1]:

array([[1., 1., 1.],


[1., 1., 1.],
[1., 1., 1.]])

In [28]:

n.zeros(3)

Out[28]:

array([0., 0., 0.])

In [29]:

#metrices qare always 2d


#so [[(3,2),(2,3)]] not a metrix as metrix has rows and columns
#Data Type inside Array is to be same
#LIST we can add, remove, replace(it is mutable)Data Type inside Array is not recquired to
#TUPLE it uses () brackets and are immutable. (2,3,4)

#l=[1,2,3,4]=List or array [1,2,3,4,a] or [1,a,1.2,[1,3],3]=List

localhost:8888/notebooks/30 September 2022 sympy array.ipynb 2/4


11/29/22, 10:32 AM 30 September 2022 sympy array - Jupyter Notebook

In [5]:

import numpy as n
n.ones((3,2,3))

Out[5]:

array([[[1., 1., 1.],


[1., 1., 1.]],

[[1., 1., 1.],


[1., 1., 1.]],

[[1., 1., 1.],


[1., 1., 1.]]])

In [32]:

#sympy symbolic python


#to use symbols

In [35]:

import sympy
a=sympy.Rational(5,8)
print("value of a is:", a)
b=sympy.Integer(3.579)
print("value of b is:", b)

value of a is: 5/8


value of b is: 3

In [8]:

x=sympy.Symbol('x')
y=sympy.Symbol('y')
z=(x+y)+(x-y)
print("value of z is :", z)

value of z is : 2*x

localhost:8888/notebooks/30 September 2022 sympy array.ipynb 3/4


11/29/22, 10:32 AM 30 September 2022 sympy array - Jupyter Notebook

In [1]:

x,y=sympy.Symbol('x,y')
z=(x+y)+(x-y)
print("value of z is :", z)

---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Input In [1], in <cell line: 1>()
----> 1 x,y=sympy.Symbol('x,y')
2 z=(x+y)+(x-y)
3 print("value of z is :", z)

NameError: name 'sympy' is not defined

In [2]:

double=lambda x:x/2
print (double(5))

2.5

In [3]:

t= lambda x:x*x
print (t(3))

In [11]:

print('{1},{0},{2}'.format("Thoma",2,"ter") )

2,Thoma,ter

In [8]:

print('{0}:{2}:{1}'.format("Maria","Kerala",562001))

Maria:562001:Kerala

In [ ]:

localhost:8888/notebooks/30 September 2022 sympy array.ipynb 4/4

You might also like