Exam 1 Neu340

¡Supera tus tareas y exámenes ahora con Quizwiz!

np.random.random(4)

#inside the parentheses is the size that you want your array of random numbers to be > array([ 0.21698734 0.01617363 0.70382199 0.8886194 ])

requirements to create a function? def my_function(): print("hello from a function) my function > hello from a function

- def - a function name, here it is my_function - a set of parentheses (()) - a colon (:) - a code block, here it is only the print statement on line 2 A function call has the function name and the parentheses. When a function is called it runs its associated code block.

To create a for loop it needs:

- for - a new variable, i - a sequence - a colon - a code block my sequence = ["a", "b", "c", "d", "e", "f"] for i in my_sequence: print ( i + "is in the sequence")

Basics of what legal and illegal VARIABLE NAMES are

- names can only contain a-z, A-Z, 0-9, and underscores (_) - names must start with a letter or underscore - names cannot be reserved words (ex. print, int, for, if)

for i in range(3, 30, 3): print(i)

> 3 > 6 > 9 > 12 > 15 > 18 > 21 > 24 > 27

myList = [2,6,8,17] indexMe = myList[2] print(indexMe)

> 8

arr = np.array([3, 2, 0, 1]) print(np.sort(arr)) arr = np.array(['banana', 'cherry', 'apple']) print(np.sort(arr))

> [0, 1, 2, 3] > ['apple' 'banana' 'cherry']

data = numpy.zeros(10) print(data) data[5] = 200.16 print(data) print(data[5])

> [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] > [0. 0. 0. 0. 0. 200.16. 0. 0. 0. 0.] > 200.16

myList = [1,2,3,4] myList.append (5) print(myList)

> [1,2,3,4,5]

myList = [1,2,3,4,5] myList.pop(0) print(myList)

> [2,3,4,5]

x = random.random() # the variable x now contains a random number between 0 & 1 print(x) > 0.85885 if x > .5: print("x is above average") else: print("x is below average")

> x is above average

x = random.random() # the variable x now contains a random number between 0 & 1 print(x) > 0.347 if x > .8: print("x is pretty big") elif x > .5: print("x is above average but not pretty big") elif x > .2: print("x is below average but not super small") else: print("x is super small")

> x is below average but not super small

my sequence = ["a", "b", "c", "d", "e", "f"] for i in my_sequence: print ( i + "is in the sequence")

>a is in the sequence >b is in the sequence >c is in the sequence >d is in the sequence >e is in the sequence >f is in the sequence Here i is the new variable, and my_sequence is the sequence the for loops iterates over my_sequence. The following data types are considered sequence data types by Python: lists, tuples, range, and strings. So, in this example we are using a list of characters as our sequence

Difference between for and while loops? Under what circumstances you might use one versus the other?

A loop is used for iterating over a set of statements repeatedly. The for statement iterates through a collection or iterable object a set number of times. The while statement simply loops until a condition is False. For loops are used when you already know the number of iterations (laps) While loops are when you don't know the number of iterations.

What is a parameter? What is an argument?

A parameter is the variable listed inside the parentheses in the function definition. An argument is the value that is sent to the function when it is called.

Bar Graph

AMOUNTS - compares quantities between independent groups/categories - change does not have to affect each other

What kind of graphs help you visualize... Amounts

Bar graphs

Heat Map

DISTRIBUTIONS - 2D distribution that uses color as the scale - can view color as the "height" as though it is coming out at you - use color as the 3rd dimension - basketball court example: the hotter the color, the more shots were taken in the court near that area - like histograms

Box Plot

DISTRIBUTIONS - each boxplot is a single histogram (there are different sets of data) - it's a simple collapsing of a distribution to show a summary - the middle half of the box plot is where the middle "chunk" falls into, the "whiskers" are those that fall further from the main half - the dots are outliers

Histogram

DISTRIBUTIONS - the abundance of something across a scale - How does a histogram differ from a bar graph? - puts the categories into bins (i.e. 18-20 yrs, 21-23 yrs...) - the groups are not independent!!! - like a pie chart A histogram is a bar graph-like representation of data that buckets a range of classes into columns along the horizontal x-axis. The vertical y-axis represents the number count or percentage of occurrences in the data for each column

What kind of graphs help you visualize... Distributions

Histograms, Box plots, Heat maps

if statement (conceptual)

If statements are control flow statements which helps us to run a particular code only when a certain condition is satisfied. If it is true then the code block is executed. If it is false then the code block is skipped and the code block isn't run. The output of the condition would either be true or false. If the outcome of condition is true then the statements inside the body of 'if' executes, however if the outcome of condition is false then the statements inside 'if' are skipped.

What index does a list start out?

Index 0, so first element is index 0

Pie Graph

PROPORTIONS - compares parts of a whole - adds up to 100%

What kind of graphs help you visualize... Proportions

Pie charts

What kind of graphs help you visualize... X-Y relationships

Scatterplots, Line graphs

Do you understand the basic reason why using functions can be useful and help organize your code?

Sometimes we want to execute code blocks in multiple places in our scripts. This is unlike a loop; loops will execute a code block repetitively in one spot. Say we want to find the sum of a list of numbers, it will be the same set of commands to find the sum, but we might want to sum a list in multiple places. So, to avoid the issues that arise with copy and pasting code we will use functions. Functions are just a way to refer to run the same code block at different points in your script. Functions refer to a set of commands, this is similar to how variables refer to a stored value.

distribution of group mean differences can give rise to...

The "significance" cutoff values for p < .05, etc.

When does your program enter into a while loop?

The first thing that happens when we come across a while loop is the condition check, if the condition is true then the code block is run, if the condition is false the code block is not run. The while loop starts by evaluating the condition. If the condition is met/ evaluates to true, we enter the loop and the code in the code block gets executed.

if-elif statement

The if and elif (known as else-if) statement is used to execute the specific block of codes with multiple conditions. In this, if the main if the condition goes false then another elif condition is checked. You can define a number of elif conditions as per your requirements. Think of an elif like an inside, if statement that follows the if statement. It is another checked condition if the if statement is false.

if-elif-else statement

The if elif else statement is used when we need to check multiple conditions. 1. There can be multiple 'elif' blocks, however there is only 'else' block is allowed. 2. Out of all these blocks only one block_of_code gets executed. If the condition is true then the code inside 'if' gets executed, if the condition is false then the next condition(associated with elif) is evaluated and so on. If none of the conditions is true then the code inside 'else' gets executed. *else doesn't come with a conditions, just a code to run*

numpy.random.random() function - do you know the range (highest and lowest possible values) of numbers it returns?

The numpy.random.rand() function outputs a Numpy array that contains numbers drawn from the standard UNIFORM distribution. That is, the array will contain numbers from the range [0, 1). brackets include, parentheses excluded

when comparing groups, what does the p-value of a t-test mean?

The p-value is the likelihood that the data from two different groups came from the same distribution null hypothesis is that there's no significance, no distinction from the two groups, both distributions are the same our experiment purpose is to say that there is a difference between the two-groups p-value says how different our distributions are want small p-value so that it shows that our groups are different

If it entered, when does your program exit a while loop?

The program exits a while loop when a condition is false/not met.

difference between np.random.random() and np.random.normal()

When we use random.random, the computer picks a number between the range 0-1 and all numbers are equally possible. This is called a flat distribution, but there is a feature in the numpy family that chooses numbers from normal distributions: numpy.random.normal. This is more useful since most of the data we work with comes from a normal distribution.

logic of a while loop

While loop is used to iterate over a block of code repeatedly until a given condition returns false. 1. First the given condition is checked, if the condition returns false, the loop is terminated and the control jumps to the next statement in the program after the loop. 2. If the condition returns true, the set of statements inside the loop are executed and then the control jumps to the beginning of the loop for next iteration. These two steps happen repeatedly as long as the condition specified in while loop remains true.

Scatter Plot

X-Y RELATIONSHIPS - how two quantitative variables relate to each other

Line Graph

X-Y/TIME SERIES - when x-represents time or increasing quantity connect the dots that are part of the same dataset

Can you assign a number or a string to a variable?

Yes! x = 7 my_string = "hello world" print(x) print(my_string) > 7 > hello world

range(1, 10, 2)

[1, 3, 5, 7, 9]

if-else statement

a more thorough version of an if statement that stipulates what is to happen when a certain criteria is not met Sometimes we don't want to skip the code block and we want an either or scenario. The if-else statement allows for execution of one code block or another If the first statement under "if" is true then the computer will run that. If its false then the code with run what is under the "else" statement.

Integer variable

a positive or negative whole number without decimals

what does the append() function do?

adds an element to the end of the list *Think Append, Add*

String variable

characters, which can be defined with single ' or double " quotes strings can be numbers as well ex."1234"

if-else flow chart

condition = TRUE -> code inside the IF body -> code after else statement condition = FALSE -> code inside the ELSE body -> code after else statement

if statement flowchart

condition = TRUE -> code inside the body -> code after if statement condition = FALSE -> code after if statement

for i in range (x, y, z):

for i in range(starting_num, ending_num, increase_by): In the above example, we have iterated over a list using for loop. However we can also use a range() function in for loop to iterate over numbers defined by range().

for i in range(0, 10): print("don't want to type this 10 times") >don't want to type this 10 times >don't want to type this 10 times >don't want to type this 10 times (continues on 10 x)

i = a counter range (0,10) = returns a sequence of numbers that begins with the first number, 0, and ends right before it gets to the second number, 10 (0 counts as a number here, 10 does not so 0-9 = 10 counts/iterations) : = we need for a block of code

importance of index variable for loops

i is the index variable and it is a useful counter!

load a csv file into Python using the Pandas library

import pandas as pd df = pd.read_csv (r'Path where the CSV file is stored\File name.csv') print (df)

syntax for built-in functions related to objects like a list like listname.sort()? Here, listname refers to a list that you have already created and called listname

nameOfTheList.sort() arrayName.sort()

numpy.random.normal()

numData = 23 data = np.random.normal(100, 20, numData) > [119.19545166 119.48134125 105.95746831 129.3124132 ...x23] np.random.normal (mean, standard deviation, #observations/data point)

Float variable

numbers that contain decimals (includes 1.0, 4.0, etc.)

numpy.random.normal() (generate dataset)

numpy.random.normal(mean, standard deviation, size/number of datapoints)

code for line graph using matplotlib

plt.plot(x,y) = line graph

code for scatterplot using matplotlib

plt.scatter(x,y) = scatter plot

Bootstrapping

random points on distribution , take means for that, take a distribution out of the means

When two arguments are used for range(), what do they mean? range(5, 9)

range(start, stop): generates a set of whole numbers starting from start to stop-1 (stop minus 1). example is equivalent to: [5, 6, 7, 8]

When are three arguments used, and what is the purpose of the third argument?

range(start, stop, step_size): generates a set of whole numbers starting from start to stop-1 (stop minus 1). The default step_size is 1 which is why when we didn't specify the step_size, the numbers generated are having a difference of 1. However by specifying step_size we can generate numbers having the difference of step_size. step size is increment of increase

What does the pop() function do?

removes the element at the SPECIFIED position *Pop is Position so index matters, pop it out of the list*

t-test/parametric vs bootstrap?

t-test you have to make an assumption about the distribution but for bootstraps there are no assumptions.


Conjuntos de estudio relacionados

Cisco Network Administration - Chapter 1

View Set

food safety and sanitation chapter 2

View Set

Microeconomics 2106 Homework Set #11

View Set

The Standard Rosary Prayer (without Mysteries)

View Set

artbgvjuewbh/iofjwghEWDKQPOEFJDIOBVKJN

View Set

AIS Midterm 2 Study Review (5,7,8,9,10)

View Set

EMT - Chapter 17: Neurologic Emergencies - Questions (MFD)

View Set

Alliteration, Analogy, Antithesis, Allusion, Anecdote

View Set