This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pylab | |
import numpy as np | |
def loadFile(): | |
inFile = open('julyTemps.txt') | |
high = [];vlow = [] | |
for line in inFile: | |
fields = line.split() | |
if len(fields) != 3 or 'Boston' == fields[0] or 'Day' == fields[0]: | |
continue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pylab | |
def loadfile(): | |
inFile = open('julyTemps.txt', 'r') | |
high =[]; low = [] | |
for line in inFile: | |
fields = line.split() | |
if len(fields) < 3 or not fields[0].isdigit(): | |
pass | |
else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Boston July Temperatures | |
------------------------- | |
Day High Low | |
------------ | |
1 91 70 | |
2 84 69 | |
3 86 68 | |
4 84 68 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load contents of text file into a list | |
# numList | |
NUMLIST_FILENAME = "IntegerArray.txt" | |
inFile = open(NUMLIST_FILENAME, 'r') | |
with inFile as f: | |
numList = [int(integers.strip()) for integers in f.readlines()] | |
count = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python | |
import sys | |
def combinations_sum(n): | |
k = n/2 | |
combs = [] | |
answers = [] | |
for i in range(0,k+1): | |
a,b = i, n-i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% function to generate permutation matrices given the size of the desired permutation matrices | |
function x = permMatrices(n) | |
x = zeros(n,n,factorial(n)); | |
permutations = perms(1:n); | |
for i = 1:size(x,3) | |
x(:,:,i) = eye(n)(permutations(i,:),:); | |
end | |
endfunction |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
m = | |
ans(:,:,1) = | |
0 1 0 0 | |
0 0 1 0 | |
1 0 0 0 | |
0 0 0 1 | |
ans(:,:,2) = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ans(:,:,1) = | |
0 1 0 | |
0 0 1 | |
1 0 0 | |
ans(:,:,2) = | |
0 0 1 | |
1 0 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Solution for part (a) | |
p = permMatrices(3); | |
n = size(p,3); % number of permutation matrices | |
v = zeros(n,1); % vector of zeros with dimension equalling number of permutation matrices | |
% check for permutation matrices other than identity matrix with 3rd power equalling identity matrix | |
for i = 1:n | |
if p(:,:,i)^3 == eye(3) | |
v(i,1) = 1; | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# INTRODUCTION TO dplyr AND tbls | |
# Load the dplyr package | |
library(dplyr) | |
# Load the hflights package | |
library(hflights) | |
# Call both head() and summary() on hflights | |
head(hflights) | |
summary(hflights) |