I hereby claim:
- I am hschafer on github.
- I am hschafer (https://keybase.io/hschafer) on keybase.
- I have a public key ASBqUJyZR7zm7SvjwwJFtw46Y5M3jmXIWIkjn8RFrGGXDQo
To claim this, I am signing this object:
StateName,Abbreviation,Popestimate2015,Popest18Plus2015,Uid,Name,Age,Gender,Raceethnicity,Month,Day,Year,Streetaddress,City,State,Classification,Lawenforcementagency,Armed,Table Name,Unarmed,Was Armed,CombinedDate,Age (bin) | |
Alaska,AK,"738,432","552,166","2,016,150",Patricia Kruger,38,Female,Native American,February,22,2016,Hawk Ln,Houston,AK,Gunshot,Alaska Department of Public Safety,Firearm,the-counted-2016.csv,null,1,2/22/16,35 | |
Alaska,AK,"738,432","552,166",79,Larry Kobuk,33,Male,Native American,January,28,2015,"Corrections Department, 1400 E 4th Ave",Anchorage,AK,Death in custody,Anchorage Department of Corrections,No,the-counted-2015.csv,1,null,1/28/15,30 | |
Alaska,AK,"738,432","552,166","2,016,587",Benjamin Zeckovic,23,Male,White,July,12,2016,400 Rodeo Pl,Anchorage,AK,Gunshot,Anchorage Police Department,Other,the-counted-2016.csv,null,1,7/12/16,20 | |
Alaska,AK,"738,432","552,166","2,016,113",Vincent Nageak III,36,Male,Native American,February,10,2016,7400 N Star St,Barrow,AK,Gunshot,North Slope Borough Police |
I hereby claim:
To claim this, I am signing this object:
So it seems like it takes an SFrame
with the tf-idf scores
name | tf-idf
---------------------
Obama | {'a': 0.1, 'b': 0.2}
Bush | {'a': 0.3, 'b': 0.4, 'c': 0.5}
After both steps to make triple x
should have
Author: Porter Jones
We've had some practice with collections throughout the quarter, but thought there were a few important points that were worth reiterating as we begin to revisit collections problems in preparation for the final.
As a reminder, for-each loops are very useful when performing read-only operations on collections. They also tend to be much nicer for readability than a typical index-based for loop. For example, imagine we want to write a method printValues that prints out all the values in a given Set
of numbers. The following method is an excellent example of when to use a for-each loop:
Today we talked about a ton of details about Java's collections and many of the Java features that get used there. Here is a short overview of the things we discussed since there were many small details.
Before we had to write classes like ArrayIntList
where we would write
public class ArrayIntList {
private int[] elementData;
private int size;
In lecture today, we reviewed the ArrayList
class and how to be clients of that data structure. We talked about how ArrayList
is a generic class because you can create ArrayList
s to hold different types of data. In class we talked about ArrayList<String>
but you could put any object type between the <>
(e.g. ArrayList<Scanner>
, ArrayList<Random>
, even ArrayList<ArrayList<String>>
!).
This idea of generic structures should be familiar to you since we have seen this before when we first learned arrays. In Java, you can have an array of String (String[]
), array of scanners (Scanner[]
), or even an array of ints (int[]
); it's the exact same idea with slightly different syntax.
What if we wanted to make an ArrayList
that held ints? Your first guess would follow the example syntax from the arrays and say ArrayList
, but this unfortunately does not work! There is a subtle difference between the generics of structures like ArrayList
and arrays: generics for structure
Say we have an ArrayIntList
object that we want to view the contents of. This could be valuable in a number of situations, for example when presenting data as part of our program or even when attempting to debug a program that uses ArrayIntList
objects. We might try to write the following code:
ArrayIntList list = new ArrayIntList();
list.add(4);
list.add(7);
list.add(-3);
System.out.println(list);
We have learned a lot this week about object-oriented programming:
These are all concepts that can be pretty tricky to wrap your head around the first time you see them since they require a pretty different way to think about the programs than what you are used to.
In lecture we saw that each type of collection has an interface (e.g. List
, Set
) and various implementations that implement those interfaces (e.g. ArrayList
/LinkedList
for List
and TreeSet
/HashSet
for Set
). We use interfaces to make our code more general; for example we can write code that works with any Set
rather than having to write it once to work for TreeSet
and another time for HashSet
.
In Java, interfaces are used to make the code more general by making a promise that any class that implements the interface is guaranteed to have those methods. In this reading, we will see how to write an interface and make your classes implement them.
Writing an interface is very similar to writing a class, but you use the keyword interface
instead of class
.
For example, we are going to make an IntList
interface that acts like Java's List
but to go along with our ArrayIntList
. We'll see next week another way to implement an IntList
called a `LinkedI
For your next programming assignment, you will be working with many objects so we wanted to spend today's reading reviewing reference semantics.
It's really important that you have the correct mental model of how Java stores information in order to understand what is going on in many of the programs we write in 143.
When you write the lines of code
int x = 5;