Asks for True or False but solution shows an array

Link to project: https://www.codecademy.com/courses/intro-statistics-numpy/projects/betty-bakery

Hi, I just need a clarification on this instruction. On Task 6, it asks which recipes require one egg and says to use a logical statement to get “True” or “False” for each value of eggs.

The solution shows the code one_egg = recipes[(eggs == 1)] and the output is an array. Am I misunderstanding what the task is asking for? It asks for which recipes and then want us to use a logical statement to GET “True” or “False” value for each value of the variable “eggs”. That means it wants boolean result and not an array, no?

The way I did it: one_egg_bool = (eggs == 1)

I guess if you stripped off the second half of that problem so that it was limited to- “Which recipes require exactly 1 egg?” then there’s an argument for returning the recipes themselves with recipes[eggs == 1]. If you take that as the main target then the second part is merely guidance on how to do it.

It does read a bit like an absolute though, “Use a logical statement to get True or False for each value of Eggs”, as in you should return just a boolean array. I think the wording is just a little imperfect.

2 Likes

I think the instructions are a bit old/outdated b/c this project is from a data analysis course (that I took circa 2017-2018(?)) that I think they just re-used/added to the computer science course.

When I did the project, I used the following:

one_egg = np.array([eggs == 1])

which will give you an array:
[[False True True False]]

Documentation:
https://numpy.org/doc/stable/reference/generated/numpy.array.html

2 Likes

Thank you guys, for the responses. I did exactly as you did @lisalisaj until I saw the solution video. The way I understood it is that I’d need to get the recipes that required only 1 egg, which also means indexing is needed, and then inside the index, we use a logical statement to test for the variable eggs and the number 1. False will of course not return anything but if it’s True, then it’ll show the recipes that only require 1 egg. Though I might wrong about it… As you said @tgrtim, the second part is to guide us to find the recipes that required only 1 egg.

2 Likes

I think if you understand both options: how to create a boolean array from your existing array and how to index an existing array with such a boolean array then you can happily move on :slightly_smiling_face:.

At least for my part I’d worry less about the question and more about the knowledge. Which is fine until one of your higher-ups/clients gives you oddly worded requests :laughing:.

2 Likes