Python Numpy Integer Exercises

1. Write a Python Numpy program to obtain the square and cubic of initial array.

The output is:

Initial array [0, 1, 2, 3, 4, 5]

Expected Answer:
Square of array: [ 0 1 4 9 16 25]
Cubic of array: [ 0 1 8 27 64 125]

Click for the answer

2. Write a Python Numpy program to generate a new array after divided by two from initial array.

The output is:

Initial array = [1, 2, 3, 4, 5]

Expected Answer:
Initial array: [1 2 3 4 5]
New array: [0.5 1. 1.5 2. 2.5]

Click for the answer



3. Write a Python Numpy program to generate the addition, subtraction, multiplication and division of two values.

The output is:

Value = 2 and 5

Expected Answer:
Addition of 2 and 5 is 7
Subtraction of 2 and 5 is -3
Multiplication of 2 and 5 is 10
Division of 2 and 5 is 0.4

Click for the answer



4. Write a Python Numpy program to calculate the division of a list of number with number 2 then obtain the remainder of the division.

The output is:

Initial array = [1, 2, 3, 4, 5]

Expected Answer:
Initial array: [1 2 3 4 5]
The remainder of division 2: [1 0 1 0 1]

Click for the answer



5. Write a Python Numpy program to round all the numbers in the initial array to its nearest whole number.

The output is:

Initial array = [0.1, 2.4, -7.8, 3.7, 4.3, 5.6]

Expected Answer:
Initial array: [ 0.1 2.4 -7.8 3.7 4.3 5.6]
Round to nearest whole number: [ 0. 2. -8. 4. 4. 6.]

Click for the answer



6. Write a Python Numpy program to round up and down all the numbers in the initial array.

The output is:

Initial array = [0.1, 2.4, -7.8, 3.7, 4.3, 5.6]

Expected Answer:
Initial array: [ 0.1 2.4 -7.8 3.7 4.3 5.6]
Round down the numbers: [ 0. 2. -8. 3. 4. 5.]
Round up the numbers: [ 1. 3. -7. 4. 5. 6.]

Click for the answer



7. Write a Python Numpy program to obtain the product of two matrixes, x and y.

The output is:

x: [[1, 2], [3, 4]]
y: [[5, 6], [7, 8]]

Expected Answer:
First Matrix:
x: [[1, 2], [3, 4]]
Second Matrix:
y: [[5, 6], [7, 8]]
Matrix product of x and y:
[[19 22]
[43 50]]

Click for the answer



8. Write a Python Numpy program to obtain the product of two matrixes, a and b with complex number.

The output is:

a = [1+2j, 3+4j]
b = [5+6j, 7+8j]

Expected Answer:
First matrix:
[1.+2.j 3.+4.j]
Second matrix:
[5.+6.j 7.+8.j]
Product of two matrixes:
(70-8j)

Click for the answer



9. Write a Python Numpy program to convert the angles from degrees to radians

The output is:

a = [-360., -270., -180., -90., 90., 180., 270., 360.]

Expected Answer:
Initial angles in degrees:
[-360. -270. -180. -90. 90. 180. 270. 360.]
Convert to radians:
[-6.28318531 -4.71238898 -3.14159265 -1.57079633 1.57079633 3.14159265 4.71238898 6.28318531]

Click for the answer



10. Write a Python Numpy program to convert the angles from radians to degrees.

The output is:

a = [-np.pi*2, -np.pi*3/2, -np.pi, -np.pi/2, np.pi/2, np.pi, np.pi*3/2, np.pi*2]

Expected Answer:
Initial angles in radians:
[-6.28318531 -4.71238898 -3.14159265 -1.57079633 1.57079633 3.14159265
4.71238898 6.28318531]
Convert to degrees:
[-360. -270. -180. -90. 90. 180. 270. 360.]

Click for the answer



                               


More Exercises:

Python String Exercises
Python List Exercises
Python Library Exercises
Python Sets Exercises
Python Array Exercises
Python Condition Statement Exercises
Python Lambda Exercises
Python Function Exercises
Python File Input Output Exercises
Python Tkinter Exercises


More Numpy Exercises:

Numpy String Exercises
Numpy Integer Exercises
Numpy Array Exercises
Numpy Data Analysis Exercises
Numpy Data Sorting Exercises


More Pandas Exercises:

Pandas Series Exercises


More Tutorials:

Python Installation - Linux (Ubuntu)
Python Installation - Mac OS
Integrated Development Environment - IDE
Python - Basic Variables
Python - Sequence Introduction
Python - Output Formatting
Python - Escape Character
Python - Type Conversion
Python - Numbers
Python – Arithmetic Operators
Python – Assignment Operators
Python – Comparison Operators
Python – Logical Operators
Python – Precedence and Associativity Operators
Python – Bytes Type and Usage
Python – Long & Raw Strings
Python – Concatenate Function
Python – Slice Function
Python – Length and Split Function
Python – Join and Count Function
Python – Find Function
Python – Index Function
Python – Alignment Function
Python – Startswith and Endswith Function
Python – String Case Conversion
Python – Remove Specified Character
Python – Encode and Decode Function
Python – dir and help Function
Python – Input Output Introduction
Python – Basic Operation
Python – Open Function
Python – Read Function
Python – Readline Function
Python – Write Function
Python – Close Function
Python – Seek and Tell Function
Python – Pickle Module
Python - File Input Module and Linecache Module
Python - Pathlib Module
Python - Pathlib Module
Python - os.path Module
Python - fnmatch Module
Python - Tuple Introduction
Python - List Introduction
Python - List Add Element
Python - List Delete Element
Python - List Modification Element
Python - List Find Element
Python - Dictionary Introduction
Python - Dictionary Basic Operation
Python - Dictionary Method Guide
Python - Set Collection
Python - Set Basic Operation
Python - Set Basic Method
Python - Frozenset Method
Python - If Condition I
Python - If Condition II
Python - While loop
Python - For loop
Python - Pass Statement
Python - Break Statement
Python - Zip Reverse Function
Python - Function Introduction
Python - Positional Parameters
Python - Key Arguments
Python - None and Return
Python - Variable Scope
Python - Local Function
Python - Closure Method
Python - Lamdba Expression