You are on page 1of 2

>> Mathematical and Trignometrical Functions Using numpy module

np.pi
np.sin
np.cos
np.tan
np.arcsin
np.arccos
np.arctan
np.arcsinh
np.arccosh
np.arctanh
np.arctan2
np.radians
np.rad2deg
np.deg2rad
np.radians
np.sinc
np.sinh
np.tanh
np.angle

Concatenation of array using numpy


import numpy as np
a = np.array([[1,2],[3,4]])

print 'First array:'


print a
print '\n'
b = np.array([[5,6],[7,8]])

print 'Second array:'


print b
print '\n'
# both the arrays are of same dimensions

print 'Joining the two arrays along axis 0:'


print np.concatenate((a,b))
print '\n'

print 'Joining the two arrays along axis 1:'


print np.concatenate((a,b),axis = 1)

Its output is as follows −


First array:
[[1 2]
[3 4]]

Second array:
[[5 6]
[7 8]]

Joining the two arrays along axis 0:


[[1 2]
[3 4]
[5 6]
[7 8]]

Joining the two arrays along axis 1:


[[1 2 5 6]
[3 4 7 8]]

>>Aliasing

In computing, aliasing describes a situation in which a data location in memory can be accessed through different
symbolic names in the program. ... Thus, modifying the data through one name implicitly modifies the values associated
with all aliased names, which may not be expected by the programmer.

>>Shallow Copy

In computing, aliasing describes a situation in which a data location in memory can be accessed through different
symbolic names in the program. ... Thus, modifying the data through one name implicitly modifies the values associated
with all aliased names, which may not be expected by the programmer.

>>Deep Copy
Deep copy is a process in which the copying process occurs recursively. ... In case of deep copy, a copy of object
is copied in other object. It means that any changes made to a copy of object do not reflect in the original object.
In python, this is implemented using “deepcopy()” function.

>>Matrices using numpy

To generate 2D matrix we can use np. arange() inside a list. We pass this list into np. array() which makes it a
2D NumPy array.2

A = [[1, 4, 5, 12],
[-5, 8, 9, 0],
[-6, 7, 11, 19]]

print("A =", A)
print("A[1] =", A[1]) # 2nd row
print("A[1][2] =", A[1][2]) # 3rd element of 2nd row
print("A[0][-1] =", A[0][-1]) # Last element of 1st Row

column = []; # empty list


for row in A:
column.append(row[2])

print("3rd column =", column)

output

A = [[1, 4, 5, 12], [-5, 8, 9, 0], [-6, 7, 11, 19]]


A[1] = [-5, 8, 9, 0]
A[1][2] = 9
A[0][-1] = 12
3rd column = [5, 9, 11]

You might also like