Question about Betty's Backery (Learn Statistics with NumPy)

Hi everyone, I’m finishing up the introductory module of Learn Statistics with NumPy and working through the project “Betty’s Bakery.”

The program let me pass with the following code, but it still brings up an error in the console and won’t print my grocery list out correctly.

import numpy as np # numpy has to be lowercase

cupcakes = ([2, 0.75, 2, 1, 0.5])

recipes = np.genfromtxt('recipes.csv', delimiter=',')

print recipes

eggs = recipes[:,2]

one_egg = recipes[(eggs == 1)]

print one_egg

cookies = recipes[2,:]

double_batch = cupcakes * 2 # 2 batches of cupcakes

grocery_list = cookies + double_batch

print grocery_list

Also, I checked the video walkthrough and my code is identical, so I don’t know why I get this error message in the console:

Traceback (most recent call last):
  File "", line 14, in <module>
    grocery_list = double_batch + cookies
ValueError: operands could not be broadcast together with shapes (10,) (5,) 

I’m a total newb so any insight would be appreciated. :slight_smile:

That error arises when you’re trying to add two arrays of two different shapes, ie: ([1, 2, 3]) , ([4])

Double check how you did step 2. Shouldn’t you use the .array() method to create an array? Ex:
cupcakes = np.array([.......])?

Also, double check step six.

“Which recipes require exactly 1 egg? Use a logical statement to get True or False for each value of eggs .”
So, how would you write that?

Here’s the cheatsheet for Numpy:

Ohh, shoot, there it is. Now I feel a little silly. Thank you!

1 Like

No, don’t feel silly at all b/c there’s no need to!

You probably also helped someone else out by posting! :slight_smile:

1 Like