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

Test whether a number is scalar or not using NumPy.

In this python numpy program, we will test whether a number is scalar or not using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Test whether a number is scalar or not using np.isscalar().
  4. Print the output.
				
					import numpy as np
x = 8.9
print(np.isscalar(x))

y = [8.9]
print(np.isscalar(y))
				
			

Output: 

				
					True
False
				
			

test element-wise for real numbers of a given array.

test whether two arrays are element-wise equal.

Test element-wise for real numbers of a given array using NumPy.

In this python numpy program, we will test element-wise for real numbers of a given array using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Test element-wise for real numbers of a given array using np.isreal().
  4. Print the output.
				
					import numpy as np
x = np.array([2,4,6+9j,7])

print(np.isreal(x))
				
			

Output :

				
					[ True  True False  True]
				
			

test element-wise for complex numbers of a given array.

test whether a number is scalar or not.

Test element-wise for complex numbers of a given array using NumPy.

In this python numpy program, we will test element-wise for complex numbers of a given array using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array()
  3. Test element-wise for complex numbers of a given array using np.iscomplex().
  4. Print the output.
				
					import numpy as np
x = np.array([2,4,6+9j,7])

print(np.iscomplex(x))
				
			

Output :

				
					[False False  True False]
				
			

test element-wise for NaN of a given array.

test element-wise for real numbers of a given array.

Test element-wise for NaN of a given array using NumPy.

In this python numpy program, we will test element-wise for NaN of a given array using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. test element-wise for NaN of a given array using np.isnan().
  4. It will return True if an element is NaN (i.e. not a number).
  5. Print the output.
				
					import numpy as np
x = np.array([2,4,np.nan,7])

print(np.isnan(x))
				
			

Output :

				
					[False False  True False]
				
			

test a given array element-wise is finite or not.

test element-wise for complex numbers of a given array.