-1

The below code I am trying to do in jupyter notebook and in this i am not possible to do dot product of two matrices

# creating random array
 
np.random.seed(0)
sales_amounts = np.random.randint(20 , size=(5,3))
sales_amounts


# creating weekly sales dataframe

weekly_sales = pd.DataFrame(sales_amounts, index =["Mon","Tues","Wed","Thur","Fri"],
                          columns =["Almond Butter","Peanut Butter","Cashew Butter"])
weekly_sales

# Create the price array
    
    prices = np.array([10,8,12])
    prices

    prices.shape


#Create butter prices dataframe

    butter_prices = pd.DataFrame(prices.reshape(1,3), index=["price"],columns= ["Almond  Butter","Peanut_Butter","Cashew Butter"])
    butter_prices


# shapes not aligned lets transpose

    total_sales = prices.dot(sales_amounts.T)
    total_sales


    #creating daily sales
  
butter_prices.shape,weekly_sales.shape


daily_sales = butter_prices.dot(weekly_sales.T)

After executing the above code in jupyter notebook it shows as error: matrices are not aligned

albert
  • 8,285
  • 3
  • 19
  • 32
Arun
  • 1
  • 4

1 Answers1

0

enter image description here

Solution:

np.dot(butter_prices, weekly_sales.T) works

Explanation:

Read the first answer from this thread that explains why this is happening.

Nick Vu
  • 14,512
  • 4
  • 21
  • 31
Lennert Antson
  • 101
  • 2
  • 4