<jupyter_start><jupyter_text>Element-wise operations<jupyter_code>values = [1,2,3,4,5]
for i in range(len(values)):
    values[i] += 5

values<jupyter_output><empty_output><jupyter_text>Numpy way<jupyter_code>import numpy as np
values = [1,2,3,4,5]
values = np.array(values) + 5
values
arr = np.array([1,2,3,4])
arr*2
np.multiply(arr, 2)
arr*0
arr<jupyter_output><empty_output><jupyter_text>**Important Reminders About Matrix Multiplication**- The number of columns in the left matrix must equal the number of rows in the right matrix.- The answer matrix always has the same number of rows as the left matrix and the same number of columns as the right matrix.- Order matters. Multiplying A•B is not the same as multiplying B•A.- Data in the left matrix should be arranged as rows., while data in the right matrix should be arranged as columns.- If you keep these four points in mind, you should always be able to figure out how to properly arrange your matrix multiplications when building a neural network.<jupyter_code>arr.ndim
arr = np.array([[1,2],[3,4]])
arr.ndim<jupyter_output><empty_output><jupyter_text>ASSIGNMENT  Use the numpy libraryimport numpy as npdef prepare_inputs(inputs):     TODO: create a 2-dimensional ndarray from the given 1-dimensional list;           assign it to input_array    input_array = None         TODO: find the minimum value in input_array and subtract that           value from all the elements of input_array. Store the           result in inputs_minus_min    inputs_minus_min = None     TODO: find the maximum value in inputs_minus_min and divide           all of the values in inputs_minus_min by the maximum value.           Store the results in inputs_div_max.    inputs_div_max = None     return the three arrays we've created    return input_array, inputs_minus_min, inputs_div_max    def multiply_inputs(m1, m2):     TODO: Check the shapes of the matrices m1 and m2.            m1 and m2 will be ndarray objects.               Return False if the shapes cannot be used for matrix           multiplication. You may not use a transpose    pass     TODO: If you have not returned False, then calculate the matrix product           of m1 and m2 and return it. Do not use a transpose,           but you swap their order if necessary    pass    def find_mean(values):     TODO: Return the average of the values in the given Python list    passinput_array, inputs_minus_min, inputs_div_max = prepare_inputs([-1,2,7])print("Input as Array: {}".format(input_array))print("Input minus min: {}".format(inputs_minus_min))print("Input  Array: {}".format(inputs_div_max))print("Multiply 1:\n{}".format(multiply_inputs(np.array([[1,2,3],[4,5,6]]), np.array([[1],[2],[3],[4]]))))print("Multiply 2:\n{}".format(multiply_inputs(np.array([[1,2,3],[4,5,6]]), np.array([[1],[2],[3]]))))print("Multiply 3:\n{}".format(multiply_inputs(np.array([[1,2,3],[4,5,6]]), np.array([[1,2]]))))print("Mean == {}".format(find_mean([1,3,4])))<jupyter_code>lst=list(range(1,11))
np.mean(lst)
lst
np.array(lst)[None,:]
arr = np.array(lst)
print(arr.shape)
print(arr.ndim)
two_dim = arr[None,:]
two_dim.ndim
two_dim
minimal = np.min(two_dim)
np.max(two_dim)
two_dim-minimal
a=np.array([[1,2,3],[4,5,6]])
b=np.array([[1],[2],[3]])

if a.shape[1]!=b.shape[0]:
    print('not compatible')
else:
    print('good to go')
a.shape,b.shape
np.matmul(a,b)
a=np.array([[1,2,3],[4,5,6]])
b=np.array([[1,2]])
np.matmul(b,a)
b.shape
a.shape
b.shape[0]
lst
np.array([lst]).ndim<jupyter_output><empty_output><jupyter_text>SOLUTION<jupyter_code># Use the numpy library
import numpy as np


def prepare_inputs(inputs):
    # TODO: create a 2-dimensional ndarray from the given 1-dimensional list;
    #       assign it to input_array
    input_array = np.array(inputs)[None, :]
#     or
#     input_array = np.array([inputs])
    
    # TODO: find the minimum value in input_array and subtract that
    #       value from all the elements of input_array. Store the
    #       result in inputs_minus_min
    inputs_minus_min = input_array - np.min(input_array)

    # TODO: find the maximum value in inputs_minus_min and divide
    #       all of the values in inputs_minus_min by the maximum value.
    #       Store the results in inputs_div_max.
    inputs_div_max = inputs_minus_min / np.max(inputs_minus_min)

    # return the three arrays we've created
    return input_array, inputs_minus_min, inputs_div_max
    

def multiply_inputs(m1, m2):
    # TODO: Check the shapes of the matrices m1 and m2. 
    #       m1 and m2 will be ndarray objects.
    #
    #       Return False if the shapes cannot be used for matrix
    #       multiplication. You may not use a transpose
    if m1.shape[1]!=m2.shape[0] and m2.shape[1]!=m1.shape[0]:
        return False


    # TODO: If you have not returned False, then calculate the matrix product
    #       of m1 and m2 and return it. Do not use a transpose,
    #       but you swap their order if necessary
    if  m1.shape[1] == m2.shape[0]:
        return np.matmul(m1,m2)
    else:
        return np.matmul(m2,m1)
    

def find_mean(values):
    # TODO: Return the average of the values in the given Python list
    return np.mean(values)


input_array, inputs_minus_min, inputs_div_max = prepare_inputs([-1,2,7])
print("Input as Array: {}".format(input_array))
print("Input minus min: {}".format(inputs_minus_min))
print("Input  Array: {}".format(inputs_div_max))

print("Multiply 1:\n{}".format(multiply_inputs(np.array([[1,2,3],[4,5,6]]), np.array([[1],[2],[3],[4]]))))
print("Multiply 2:\n{}".format(multiply_inputs(np.array([[1,2,3],[4,5,6]]), np.array([[1],[2],[3]]))))
print("Multiply 3:\n{}".format(multiply_inputs(np.array([[1,2,3],[4,5,6]]), np.array([[1,2]]))))

print("Mean == {}".format(find_mean([1,3,4])))<jupyter_output>Input as Array: [[-1  2  7]]
Input minus min: [[0 3 8]]
Input  Array: [[0.    0.375 1.   ]]
Multiply 1:
False
Multiply 2:
[[14]
 [32]]
Multiply 3:
[[ 9 12 15]]
Mean == 2.6666666666666665
{'fraction_non_alphanumeric': 0.1325180097168705, 'fraction_numerical': 0.0326687887418328, 'mean_word_length': 4.055038103302286, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '449832', 'license': 'MIT', 'n_tokens_mistral': 2103, 'n_tokens_neox': 2006, 'n_words': 605, 'path': 'UDACITY DL Nanodegree/Introduction to Neural Network/Matrices.ipynb', 'repo_name': 'NirmalSilwal/Deep-Learning', 'size': '5969'}