Sarah111-AHM / Semsmah

2 stars 0 forks source link

LAP(3) #14

Open Sarah111-AHM opened 1 year ago

Sarah111-AHM commented 1 year ago
  1. Creating ndarrays: Question: Create a 3x3 numpy array with random integers between 1 and 10.

  2. Creating ndarrays:

    import numpy as np
    arr = np.random.randint(1, 10, size=(3,3))
    print(arr)

    Output:

    [[6 2 7]
    [1 2 4]
    [4 4 2]]
  3. Data Types for ndarrays: Question: Create a numpy array with the following data types: integer, float, string, boolean, and complex.

  4. Data Types for ndarrays:

    import numpy as np
    arr = np.array([1, 2.5, 'hello', True, 1+2j])
    print(arr)

    Output:

    ['1' '2.5' 'hello' 'True' '(1+2j)']
  5. Arithmetic with NumPy Arrays: Question: Create two numpy arrays of shape (2,2) with random integers between 1 and 10. Perform matrix multiplication between the two arrays and return the result.

  6. Arithmetic with NumPy Arrays:

import numpy as np
arr1 = np.random.randint(1, 10, size=(2,2))
arr2 = np.random.randint(1, 10, size=(2,2))
result = np.dot(arr1, arr2)
print(result)

Output:

[[ 33  55]
 [ 63 110]]

creating array