In mathematics, a matrix (plural matrices) is a rectangular array of numbers. Matrices have many applications in programming, from performing transformations in 2D space to machine learning. 

One of the most useful operations to perform on matrices is matrix multiplication, which takes a pair of matrices and produces another matrix – known as the dot product. Multiplying matrices is very different to multiplying real numbers, and follows its own set of rules. 

Unlike multiplying real numbers, multiplying matrices is non-commutative: in other words, multiplying matrix ```a``` by matrix ```b``` will not give the same result as multiplying matrix ```b``` by matrix ```a```.

Additionally, not all pairs of matrix can be multiplied. For two matrices to be multipliable, the number of columns in matrix ```a``` must match the number of rows in matrix ```b```.

There are many introductions to matrix multiplication online, including at Khan Academy, and in the classic MIT lecture series by Herbert Gross. 

To complete this kata, write a function that takes two matrices - ```a``` and ```b``` - and returns the dot product of those matrices. If the matrices cannot be multiplied, return ```-1``` for JS/Python, or `null` for Java.

Each matrix will be represented by a two-dimensional list (a list of lists). Each inner list will contain one or more numbers, representing a row in the matrix.

For example, the following matrix:

```|1 2|``````|3 4|```

Would be represented as:

```[[1, 2], [3, 4]]```

It can be assumed that all lists will be valid matrices, composed of lists with equal numbers of elements, and which contain only numbers. The numbers may include integers and/or decimal points.

Difficulty: introductory

Starter code:

def getMatrixProduct(a, b):
	

Solutions:
import numpy as np

def getMatrixProduct(a, b):
    try:
        return np.matmul(a, b).tolist()
    except:
        return - 1

def getMatrixProduct(a, b):
    if len(a[0]) != len(b):
        return -1
    result = [[0 for i in range(len(b[0]))] for j in range(len(a))]
    for i in range(len(a)):
        for j in range(len(b[0])):
            for k in range(len(b)):
                result[i][j] += a[i][k] * b[k][j]
    return result

def getMatrixProduct(a, b):
    if len(a[0]) != len(b):
        return -1
    return [[sum(m*n for m,n in zip(a_row, b_col)) for b_col in zip(*b)] for a_row in a]

import numpy as np

def getMatrixProduct(a, b):
    try:
        return (np.matrix(a) * np.matrix(b)).tolist()
    except ValueError:
        return -1

getMatrixProduct=lambda a,b:-((len(a)and len(a[0]))!=len(b))or[[sum(x*y for x,y in zip(r,c))for c in zip(*b)]for r in a]

getMatrixProduct=lambda a, b:-1 if len(list(zip(*a)))!=len(b) else [[sum(k*l for k,l in zip(i,j)) for j in zip(*b)]for i in a]

from numpy import matrix

def get_matrix_product(a, b):
    m1, m2 = matrix(a), matrix(b)
    return ( m1 * m2 ).tolist() if m1.shape[1] == m2.shape[0] else -1


getMatrixProduct = get_matrix_product

def getMatrixProduct(A, B):
    rows_A = len(A)
    cols_A = len(A[0])
    rows_B = len(B)
    cols_B = len(B[0])

    if cols_A != rows_B:
      print( "Cannot multiply the two matrices. Incorrect dimensions.")
      return -1

    # Create the result matrix
    # Dimensions would be rows_A x cols_B
    C = [[0 for row in range(cols_B)] for col in range(rows_A)]
    print(C)

    for i in range(rows_A):
        for j in range(cols_B):
            for k in range(cols_A):
                C[i][j] += A[i][k] * B[k][j]
    return C

import numpy as np
def getMatrixProduct(a, b):
    try: return np.dot(a, b).tolist()
    except: return -1


def getMatrixProduct(a, b):
    """If a and b can be multiplied, returns the product of a and b as a two-dimensional array. Otherwise returns -1."""
    # Get dimensions
    arl, acl = len(a), len(a[0])
    brl, bcl = len(b), len(b[0])
    # Validate compatible dimensions
    if acl != brl:
        return -1
    # Handy data extraction lambdas
    row = lambda ar, n: ar[n]
    col = lambda ar, n: [r[n] for r in ar]
    # Sum of the products of parallel arrays
    prod_sum = lambda ar1, ar2: sum((v1 * v2 for v1, v2 in zip(ar1, ar2)))
    # Answer!
    return [[prod_sum(row(a, r), col(b, c)) for c in range(bcl)] for r in range(arl)]