Create an array of odd integers between 1-20 using NumPy.

In this python numpy program, we will create an array of odd integers between 1-20 using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array of odd integers using np.arange().
  3. Print the output.
				
					import numpy as np
x = np.arange(1,21,2)

print("Array of odd numbers: ",x)
				
			

Output :

				
					Array of odd numbers:  [ 1  3  5  7  9 11 13 15 17 19]
				
			

create an array of even integers between 1-20.

create an array of integers between 1-100 by the difference of 6 between them.

Create an array of even integers between 1-20 using NumPy.

In this python numpy program, we will create an array of even integers between 1-20 using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array of even numbers using np.arange().
  3. Print the output.
				
					import numpy as np
x = np.arange(2,21,2)

print("Array of even numbers: ",x)
				
			

Output :

				
					Array of even numbers:  [ 2  4  6  8 10 12 14 16 18 20]
				
			

create an array of integers between 1-20.

create an array of odd integers between 1-20.

Create an array of integers between 1-20 using NumPy.

In this python numpy program, we will create an array of integers between 1-20 using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array of integers using np.arange().
  3. Print the output.
				
					import numpy as np
x = np.arange(1,21)

print("Array: ",x)
				
			

Output :

				
					Array:  [ 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20]
				
			

create an array of 3 ones.

create an array of even integers between 1-20.

Program to create an array of 3 ones using NumPy.

In this python numpy program, we will create an array of 3 ones using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array of 3 ones using np.ones() and give datatype as int and number of ones i.e. 3 to the above function.
  3. Print the output.
				
					import numpy as np
x = np.ones(3, dtype = int)

print(x)
				
			

Output :

				
					[1 1 1]
				
			

determine the size of the memory occupied by the above array.

create an array of integers between 1-20.

Determine the size of the memory occupied by the array using NumPy.

In this python numpy program, we will determine the size of the memory occupied by the array using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Get the size of the array using size.
  4. Get the memory occupied by the one element in the array in bytes using itemsize.
  5. Get the memory size of NumPy array in bytes using x.size * x.itemsize.
  6. Print the output.
				
					import numpy as np
x = np.array([10,34,86,26,56])

print("Size of the array: ",x.size)
print("Memory size of one array element in bytes: ", x.itemsize)
print("Memory size of numpy array in bytes:", x.size * x.itemsize)
				
			

Output :

				
					Size of the array:  5
Memory size of one array element in bytes:  4
Memory size of numpy array in bytes: 20
				
			

create an array with the values 10,34,86,26,56.

create an array of 3 ones using NumPy.

NumPy program to create an array with the values.

In this python numpy program, we will create an array with the values.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array with the given values using np.array().
  3. Print the output.
				
					import numpy as np
x = np.array([10,34,86,26,56])

print(x)
				
			

Output :

				
					[10 34 86 26 56]
				
			

create an element-wise comparison (less than).

determine the size of the memory occupied by the above array.

NumPy program to create an element-wise comparison using NumPy.

In this python numpy program, we will program to create an element-wise comparison using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create two arrays using np.array().
  3. Create an element-wise comparison less than using NumPy ( < ).
  4. Print the output.
				
					import numpy as np
x = np.array([6,4])
y = np.array([2,9])

print(x < y)
				
			

Output :

				
					[False  True]
				
			

create an element-wise comparison (greater equal).

create an array with the values 10,34,86,26,56.

NumPy program to create an element-wise comparison using NumPy.

In this python numpy program, we will create an element-wise comparison using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create two arrays using np.array().
  3. Create an element-wise comparison greater equal using ( >= ).
  4. Print the output.
				
					import numpy as np
x = np.array([6,4])
y = np.array([6,3])

print(x >= y)
				
			

Output :

				
					[ True  True]
				
			

create an element-wise comparison (greater than).

create an element-wise comparison (less than).

NumPy program to create an element-wise comparison using NumPy.

In this python numpy program, we will create an element-wise comparison using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create two arrays using np.array().
  3. Create an element-wise comparison greater than using ( > ).
  4. Print the output.
				
					import numpy as np
x = np.array([8,3])
y = np.array([9,1])

print(x>y)
				
			

Output :

				
					[False  True]
				
			

test whether two arrays are element-wise equal.

create an element-wise comparison (greater equal).

Test whether two arrays are element-wise equal using NumPy.

In this python numpy program,we will test whether two arrays are element-wise equal using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create two arrays using np.array().
  3. Test whether two arrays are element-wise equal using equal to (==).
  4. Print the output.
				
					import numpy as np
x = np.array([3,8,5])
y = np.array([3,8,5])

print(x==y)
				
			

Output :

				
					[ True  True  True]
				
			

test whether a number is scalar or not.

create an element-wise comparison (greater than).