xxxxxxxxxx
import numpy as np
# Creating an array from a list
my_list = [1, 2, 3, 4, 5]
array_from_list = np.array(my_list)
# Creating an array with zeros
array_zeros = np.zeros(5) # Creates an array of size 5 filled with zeros
# Creating an array with ones
array_ones = np.ones((2, 3)) # Creates a 2x3 array filled with ones
# Creating an array with a range of values
array_range = np.arange(1, 10, 2) # Creates an array with values 1, 3, 5, 7, 9
# Creating a random array
array_random = np.random.rand(3, 3) # Creates a 3x3 array with random values between 0 and 1
print("Array from list:\n", array_from_list)
print("\nArray of zeros:\n", array_zeros)
print("\nArray of ones:\n", array_ones)
print("\nArray with a range of values:\n", array_range)
print("\nRandom array:\n", array_random)
xxxxxxxxxx
import numpy as np
# Creating an array from a list
my_list = [1, 2, 3, 4, 5]
array_from_list = np.array(my_list)
# Creating an array with zeros
array_zeros = np.zeros(5) # Creates an array of size 5 filled with zeros
# Creating an array with ones
array_ones = np.ones((2, 3)) # Creates a 2x3 array filled with ones
# Creating an array with a range of values
array_range = np.arange(1, 10, 2) # Creates an array with values 1, 3, 5, 7, 9
# Creating a random array
array_random = np.random.rand(3, 3) # Creates a 3x3 array with random values between 0 and 1
print("Array from list:\n", array_from_list)
print("\nArray of zeros:\n", array_zeros)
print("\nArray of ones:\n", array_ones)
print("\nArray with a range of values:\n", array_range)
print("\nRandom array:\n", array_random)