Monday, 3 October 2022

Ex2. Working with Numpy arrays

 Ex2. Working with Numpy arrays

Aim:

         Working with different instructions used in Numpy array

Procedure

ü Do the following function

ü To print the array print(a)

ü To print the shape of the array print(a.shape)

ü To the function return the number of dimensions of an array. print(a.ndim)

ü This data type object (dtype) informs us about the layout of the array. print(a.dtype.name)

ü This returns the size (in bytes) of each element of a NumPy array print(a.itemsize)

ü This is the total number of elements in the ndarray. print(a.size)

 

Program

import numpy as np

a = np.arange(15).reshape(35)

To print the array

print(a)

To print the shape of the array

print(a.shape)

To the function return the number of dimensions of an array.

print(a.ndim)

This data type object (dtype) informs us about the layout of the array

print(a.dtype.name)

This returns the size (in bytes) of each element of a NumPy array

print(a.itemsize)

 This is the total number of elements in the ndarray.

print(a.size)

 

 

arr = np.array([12345678])

x = np.where(arr%2 == 1)

print(x)

Slice elements from index 1 to index 5 from the following array

print(arr[1:5])

Get third and fourth elements from the following array and add them.

print(arr[2] + arr[3])

 

Write a NumPy program to convert the values of Centigrade degrees into Fahrenheit degrees and vice versa. Values are stored into a NumPy array.

import numpy as np

fvalues = [0, 12, 45.21, 34, 99.91, 32]

F = np.array(fvalues)

print("Values in Fahrenheit degrees:")

print(F)

print("Values in  Centigrade degrees:")

print(np.round((5*F/9 - 5*32/9),2))

No comments:

Post a Comment

CCS 365 Software Defined Network Lab Manual

 CCS 365 Software Defined Network Lab Manual 1) Setup your own virtual SDN lab i) Virtualbox/Mininet Environment for SDN - http://mininet.or...