Python Exercise Lists

# 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]

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

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]

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

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

The output is:

Value = 2 and 5

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

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]

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

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]

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.]

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]

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.]

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]]

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

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]

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

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.]

Initial angles in degrees:
[-360. -270. -180. -90. 90. 180. 270. 360.]
[-6.28318531 -4.71238898 -3.14159265 -1.57079633 1.57079633 3.14159265 4.71238898 6.28318531]

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]