(X, word_to_index, max_len)
return X_indices
Converts an array of sentences (strings) into an array of indices corresponding to words in the sentences.
    The output shape should be such that it can be given to `Embedding()` 
    
    Arguments:
    X -- array of sentences (strings), of shape (m, 1)
    word_to_index -- a dictionary containing the each word mapped to its index
    max_len -- maximum number of words in a sentence. You can assume every sentence in X is no longer than this. 
    
    Returns:
    X_indices -- array of indices corresponding to words in the sentences from X, of shape (m, max_len)
Converts an array of sentences (strings) into an array of indices corresponding to words in the sentences.
    The output shape should be such that it can be given to `Embedding()` 
    
    Arguments:
    X -- array of sentences (strings), of shape (m, 1)
    word_to_index -- a dictionary containing the each word mapped to its index
    max_len -- maximum number of words in a sentence. You can assume every sentence in X is no longer than this. 
    
    Returns:
    X_indices -- array of indices corresponding to words in the sentences from X, of shape (m, max_len)
Converts an array of sentences ( strings ) into an array of indices corresponding to words in the sentences . The output shape should be such that it can be given to Embedding () Arguments : X -- array of sentences ( strings ) of shape ( m 1 ) word_to_index -- a dictionary containing the each word mapped to its index max_len -- maximum number of words in a sentence . You can assume every sentence in X is no longer than this . Returns : X_indices -- array of indices corresponding to words in the sentences from X of shape ( m max_len )
def sentences_to_indices(X, word_to_index, max_len):
    """
    Converts an array of sentences (strings) into an array of indices corresponding to words in the sentences.
    The output shape should be such that it can be given to `Embedding()` 
    
    Arguments:
    X -- array of sentences (strings), of shape (m, 1)
    word_to_index -- a dictionary containing the each word mapped to its index
    max_len -- maximum number of words in a sentence. You can assume every sentence in X is no longer than this. 
    
    Returns:
    X_indices -- array of indices corresponding to words in the sentences from X, of shape (m, max_len)
    """
    m = X.shape[0]            # number of training examples 
    # Initialize X_indices as a numpy matrix of zeros and the correct shape (≈ 1 line)
    X_indices = np.zeros((m, max_len))
    for i in range(m):                               # loop over training examples
        # split the sentences into words
        sentence_words =X[i].split(' ') 
        # Loop over the words of sentence_words
        for j,w in enumerate(sentence_words):
            if j >= max_len:
                break
            # Set the (i,j)th entry of X_indices to the index of the correct word.
            X_indices[i, j] = word_to_index[w]
            
    return X_indices
def sentences_to_indices ( X , word_to_index , max_len ) : m = X . shape [ 0 ] # number of training examples  # Initialize X_indices as a numpy matrix of zeros and the correct shape (≈ 1 line) X_indices = np . zeros ( ( m , max_len ) ) for i in range ( m ) : # loop over training examples # split the sentences into words sentence_words = X [ i ] . split ( ' ' ) # Loop over the words of sentence_words for j , w in enumerate ( sentence_words ) : if j >= max_len : break # Set the (i,j)th entry of X_indices to the index of the correct word. X_indices [ i , j ] = word_to_index [ w ] return X_indices