Lab 7: Reading Files, Importing, Bigram Function. Ling 1330/2330: Computational Linguistics Na-Rae Han

Size: px
Start display at page:

Download "Lab 7: Reading Files, Importing, Bigram Function. Ling 1330/2330: Computational Linguistics Na-Rae Han"

Transcription

1 Lab 7: Reading Files, Importing, Bigram Function Ling 1330/2330: Computational Linguistics Na-Rae Han

2 Objectives Importing Reading text files range() Bigram function More sorting with sorted() sorted() + indexing/slicing 9/18/2018 2

3 More libraries through import So far, we have been only using built-in data types and functions: int, str, list, dict, tuple, len(), print(), sum(), *, +, -, But there are tons of additional modules and packages! You gain access to them by importing. import math math.sqrt(64) 8.0 math.factorial(5) 120 Import the math module Call math functions. Must prefix math. 9/18/2018 3

4 math module import math dir(math) [' doc ', ' name ', ' package ', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'hypot', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc'] math.sqrt(144) 12.0 help(math.log) Help on built-in function log in module math: log(...) log(x[, base]) dir() and help() come in handy for exploring. Return the logarithm of x to the given base. If the base not specified, returns the natural logarithm (base e) of x. math.log(16, 2) 4.0 9/18/2018 4

5 os module os.getcwd() returns the "current working directory" (CWD) import os os.getcwd() '/Users/narae/Documents' help(os.getcwd) Help on built-in function getcwd in module nt: os provides operatingsystem-dependent functionality. getcwd() Return a unicode string representing the current working directory. os.chdir('pythoncode') os.getcwd() '/Users/narae/Documents/pythoncode' os.listdir() ['pal_loop.py', 'pal_naive.py', 'pg16328.txt', 'pig_latin.solution.py', 'pig_latin.template.py', 'secret.py', 'textstats.template.py', 'v_c_count.py', 'v_c_count_try.py', ' pycache '] 9/18/2018 5

6 os module import os os.getcwd() '/Users/narae/Documents' help(os.getcwd) Help on built-in function getcwd in module nt: getcwd() Return a unicode string representing the current working directory. os.chdir('pythoncode') os.getcwd() '/Users/narae/Documents/pythoncode' os.listdir() os.chdir() changes the "current working directory" ['pal_loop.py', 'pal_naive.py', 'pg16328.txt', 'pig_latin.solution.py', 'pig_latin.template.py', 'secret.py', 'textstats.template.py', 'v_c_count.py', 'v_c_count_try.py', ' pycache '] 9/18/2018 6

7 os module import os os.getcwd() '/Users/narae/Documents' help(os.getcwd) Help on built-in function getcwd in module nt: getcwd() Return a unicode string representing the current working directory. os.chdir('pythoncode') os.getcwd() '/Users/narae/Documents/pythoncode' os.listdir() ['pal_loop.py', 'pal_naive.py', 'pg16328.txt', 'pig_latin.solution.py', 'pig_latin.template.py', 'secret.py', 'textstats.template.py', 'v_c_count.py', 'v_c_count_try.py', ' pycache '] os.listdir() returns the list of files/dirs in the CWD 9/18/2018 7

8 Try it out 1 minute import math dir(math) math.sqrt(144) help(math.log) math.log(16, 2) import os os.getcwd() help(os.getcwd) os.listdir() os.chdir('pythoncode') Depends on your environment. See A10 "File Path and CWD". 9/18/2018 8

9 What is your default CWD? Windows users: You should NOT be seeing this! This should be your own designated Python script directory. Change your default CWD by following: 9/18/2018 9

10 What is your default CWD? Mac users: Ideally, your initial cwd should be your Python script directory Experienced users can change their default CWD by: If you don't want to mess with command-line, you will need to get in the habit of using os.chdir(). os.chdir('pytnoncode') os.getcwd() '/Users/narae/Documents/pythoncode' See A10 "File Path and CWD". 9/18/

11 fox_in_sox.txt The text has 5 lines. 9/18/

12 Opening a text file for reading f is a file object name of file to read f = open('fox_in_sox.txt', 'r') ## read from f f.close() Closes the file. ALWAYS REMEMBER TO CLOSE YOUR FILE. 'r' for reading. It is default: can be omitted May also need to specify encoding: encoding='utf-8' 9/18/

13 (1) Reading entire text as a single string f = open('fox_in_sox.txt', 'r') text = f.read() f.read() Variable text is a string obj whose value is the entire text f.close() print(text) ======================== RESTART ===================== Through three cheese trees three free fleas flew. While these fleas flew, freezy breeze blew. Freezy breeze made these three trees freeze. Freezy trees made these trees' cheese freeze. That's what made these three free fleas sneeze. print added an extra line break 9/18/

14 (2) Reading entire text as a list of lines f = open('fox_in_sox.txt') lines = f.readlines() f.close() print(lines) f.readlines() reads in the text as a list of lines. lines is a list of strings, where each string is a single line. ======================== RESTART ===================== ['Through three cheese trees three free fleas flew.\n', 'While these fleas flew, freezy breeze blew.\n', 'Freezy breeze made these three trees freeze.\n', "Freezy trees made these trees' cheese freeze.\n", "That's what made these three free fleas sneeze.\n"] 9/18/

15 Try it out 3 minutes Download file and save in your usual script directory: And try these commands, in IDLE shell f = open('fox_in_sox.txt') text = f.read() f.close() print(text) print(text.split()) f = open('fox_in_sox.txt') lines = f.readlines() f.close() print(lines) print(lines[0]) Do NOT copy and paste file content! Use "SAVE AS" dialog box in your browser to save the file ITSELF as a text file. for l in lines : if 'tree' in l : print(l) print(l, end='') prevents extra line break 9/18/

16 range() function for x in range(5, 10): print(x) starts at 5 stops BEFORE 10 9/18/

17 range() function for x in range(5, 10): print(x) for x in range(10): print(x) No starting point specified: starts at 0 9/18/

18 Practice 2 minutes Compose a for loop that prints out for every character in a word: its index, the character itself ' t i g e r ' word = 'tiger' for i in range(len(word)): print(i, word[i]) 0 t 1 i 2 g 3 e 4 r The length of the string should be the "stop-before" point. 9/18/

19 Practice 2 minutes Compose a for loop that prints out for every character in a word: its index, the character itself ' t i g e r ' word = 'tiger' for i in range(len(word)): print(i, word[i]) 0 t 1 i 2 g 3 e 4 r len(word) returns 5, range(5) generates 0, 1, 2, 3, 4 9/18/

20 word = 'tiger' for i in range(len(word)): print(i, word[i]) Practice 2 minutes 0 t 1 i 2 g 3 e 4 r word = 'tiger' for i in range(len(word)): print(i, word[i:]) 0 tiger 1 iger 2 ger 3 er 4 r ' t i g e r ' word = 'tiger' for i in range(len(word)): print(i, word[i:i+2]) 0 ti 1 ig 2 ge 3 er 4 r 9/18/

21 word = 'tiger' for i in range(len(word)): print(i, word[i]) Practice 2 minutes 0 t 1 i 2 g 3 e 4 r word = 'tiger' for i in range(len(word)): print(i, word[i:]) 0 tiger 1 iger 2 ger 3 er 4 r ' t i g e r ' word = 'tiger' for i in range(len(word)): print(i, word[i:i+2]) 0 ti 1 ig 2 ge 3 er 4 r 9/18/

22 Producing character-level bigrams txt = 'tiger' txt[0:2] ti txt[1:3] ig for i in range(len(txt)) : print(txt[i:i+2]) ti ig ge er r [i:i+2] returns a 2-character slice 1-char string at the end:* txt[4:6] How to avoid? *Slicing stopping point can be beyond index: 'penguin'[3:100] returns 'guin' just fine. 9/18/

23 Producing character-level bigrams txt = 'tiger' txt[0:2] ti txt[1:3] ig for i in range(len(txt)-1) : print(txt[i:i+2]) ti ig ge er range() input is modified so that i stops at one integer before 9/18/

24 Building a char-level bigram function Where the last gram starts: 2-gram txt = ' t i g e r ' for i in range(len(txt)-1) : gram = txt[i:i+2] Your last 2-gram should be 'er'(txt[3:5]), not 'r' (txt[4:6]) That means i should range from 0 to 3, stopping at 3. That means: len(txt) = 5 range(len(txt)) 0, 1, 2, 3, 4 range(len(txt)-1) 0, 1, 2, 3 9/18/

25 Character-level bigram function def getchar2grams(txt) : bigrams = [] for i in range(len(txt)-1) : gram = txt[i:i+2]?? bigrams.append(gram) return bigrams getchar2grams('penguin') ['pe', 'en', 'ng', 'gu', 'ui', 'in'] getchar2grams('hello, world!') ['He', 'el', 'll', 'lo', 'o,', ', ', ' w', 'wo', 'or', 'rl', 'ld', 'd!'] 9/18/

26 Character-level bigram function def getchar2grams(txt) : bigrams = [] for i in range(len(txt)-1) : gram = txt[i:i+2] bigrams.append(gram) return bigrams getchar2grams('penguin') ['pe', 'en', 'ng', 'gu', 'ui', 'in'] getchar2grams('hello, world!') ['He', 'el', 'll', 'lo', 'o,', ', ', ' w', 'wo', 'or', 'rl', 'ld', 'd!'] Character-level bigrams: tokenization of symbols not necessary 9/18/

27 Try it out 2 minutes def getchar2grams(txt) : bigrams = [] for i in range(len(txt)-1) : gram = txt[i:i+2] bigrams.append(gram) return bigrams getchar2grams('penguin') ['pe', 'en', 'ng', 'gu', 'ui', 'in'] getchar2grams('hello, world!') ['He', 'el', 'll', 'lo', 'o,', ', ', ' w', 'wo', 'or', 'rl', 'ld', 'd!'] 9/18/

28 Sorting + slicing Looking to pick out the very first N items? Returned value of sorted() can be indexed & sliced: li = ['fox', 'dog', 'cat', 'owl', 'ant'] sorted(li) ['ant', 'cat', 'dog', 'fox', 'owl'] sorted(li)[0] 'ant' sorted(li)[:2] ['ant', 'cat'] sorted(li, reverse=true)[:3] ['owl', 'fox', 'dog'] #1 ranked Top 2 Top 3, reverse ranking 9/18/

29 Population by state Find the popul dictionary in text-samples.txt Copy & paste it into IDLE shell 3 minutes Print out the #1 populous state Print out the top 10 most populous states Print out the top 5 least populous states 9/18/

30 for x in sorted(popul, key=popul.get, reverse=true)[:10]: print(x, popul[x]) ca tx ny fl il pa oh ga mi nc for x in sorted(popul, key=popul.get)[:5]: print(x, popul[x]) 10 most populous wy vt nd ak sd least populous 30

31 HW 2 review textstats.py Exercise 5 Update textstats.py with the new character-level bigram function Process how_do_i.txt 9/18/

32 Wrapping up Next class: Writing files, file and directory path, importing user-built module Exercise 5 9/18/

Programming for Engineers in Python. Recitation 2

Programming for Engineers in Python. Recitation 2 Programming for Engineers in Python Recitation 2 Plan Range For loop While loop Lists Modules Operations Arithmetic Operations: + plus - minus * multiply / divide (int / float) % modulo (remainder) **

More information

Built-in Types of Data

Built-in Types of Data Built-in Types of Data Types A data type is set of values and a set of operations defined on those values Python supports several built-in data types: int (for integers), float (for floating-point numbers),

More information

Programming for Engineers in Python. Recitation 3

Programming for Engineers in Python. Recitation 3 Programming for Engineers in Python Recitation 3 Plan Modules / Packages Tuples Mutable / Imutable Dictionaries Functions: Scope Call by Ref / Call by Val Frequency Counter Python Code Hierarchy Statement

More information

Programming for Engineers in Python. Recitation 3 Functions

Programming for Engineers in Python. Recitation 3 Functions Programming for Engineers in Python Recitation 3 Functions Plan Short review FOR and Lists Python references Mutable vs. immutable data types List references Functions Scope Call by assignment Global variables

More information

Chap 6 Function Define a function, which can reuse a piece of code, just with a few different values.

Chap 6 Function Define a function, which can reuse a piece of code, just with a few different values. Chap 6 Function Define a function, which can reuse a piece of code, just with a few different values. def tax(bill): """Adds 8% tax to a restaurant bill.""" bill *= 1.08 print "With tax: %f" % bill return

More information

(IUCAA, Pune) kaustubh[at]iucaa[dot]ernet[dot]in.

(IUCAA, Pune)   kaustubh[at]iucaa[dot]ernet[dot]in. Basics of Python by Kaustubh Vaghmare (IUCAA, Pune) E-mail: kaustubh[at]iucaa[dot]ernet[dot]in 1 of 29 Thursday 13 February 2014 11:59 AM Topics to be Covered (Not in any specific order.) Basic I/O in

More information

DM550/DM857 Introduction to Programming. Peter Schneider-Kamp

DM550/DM857 Introduction to Programming. Peter Schneider-Kamp DM550/DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ Operator Precedence expressions are evaluated left-to-right

More information

(IUCAA, Pune) kaustubh[at]iucaa[dot]ernet[dot]in 1 of 29 Thursday 16 October :50 PM

(IUCAA, Pune)   kaustubh[at]iucaa[dot]ernet[dot]in 1 of 29 Thursday 16 October :50 PM Basics of Python by Kaustubh Vaghmare (IUCAA, Pune) E-mail: kaustubh[at]iucaa[dot]ernet[dot]in 1 of 29 Thursday 16 October 2014 03:50 PM Topics to be Covered (Not in any specific order.) Basic I/O in Python

More information

Python. Olmo Zavala R. Python Exercises. Center of Atmospheric Sciences, UNAM. August 24, 2016

Python. Olmo Zavala R. Python Exercises. Center of Atmospheric Sciences, UNAM. August 24, 2016 Exercises Center of Atmospheric Sciences, UNAM August 24, 2016 NAND Make function that computes the NAND. It should receive two booleans and return one more boolean. logical operators A and B, A or B,

More information

High Level Scripting. Gino Tosti University & INFN Perugia. 06/09/2010 SciNeGhe Data Analysis Tutorial

High Level Scripting. Gino Tosti University & INFN Perugia. 06/09/2010 SciNeGhe Data Analysis Tutorial High Level Scripting Part I Gino Tosti University & INFN Perugia What is a script? Scripting Languages It is a small program able to automate a repetitive and boring job; It is a list of commands that

More information

Standard Library. Built-in Functions

Standard Library. Built-in Functions 2 The Standard Library Lab Objective: Python is designed to make it easy to implement complex tasks with little code. To that end, every Python distribution includes several built-in functions for accomplishing

More information

Lab 8: File I/O, Mutability vs. Assignment. Ling 1330/2330: Intro to Computational Linguistics Na-Rae Han

Lab 8: File I/O, Mutability vs. Assignment. Ling 1330/2330: Intro to Computational Linguistics Na-Rae Han Lab 8: File I/O, Mutability vs. Assignment Ling 1330/2330: Intro to Computational Linguistics Na-Rae Han Objectives File I/O Writing to a file File I/O pitfalls File reference and absolute path Mutability

More information

SECOND EDITION SAMPLE CHAPTER. First edition by Daryl K. Harms Kenneth M. McDonald. Naomi R. Ceder MANNING

SECOND EDITION SAMPLE CHAPTER. First edition by Daryl K. Harms Kenneth M. McDonald. Naomi R. Ceder MANNING SECOND EDITION SECOND EDITION Covers Python 3 SAMPLE CHAPTER First edition by Daryl K. Harms Kenneth M. McDonald Naomi R. Ceder MANNING The Quick Python Book Second Edition by Naomi R. Ceder Chapter 4

More information

Lab 6: Data Types, Mutability, Sorting. Ling 1330/2330: Computational Linguistics Na-Rae Han

Lab 6: Data Types, Mutability, Sorting. Ling 1330/2330: Computational Linguistics Na-Rae Han Lab 6: Data Types, Mutability, Sorting Ling 1330/2330: Computational Linguistics Na-Rae Han Objectives Data types and conversion Tuple Mutability Sorting: additional parameters Text processing overview

More information

DM536 / DM550 Part 1 Introduction to Programming. Peter Schneider-Kamp.

DM536 / DM550 Part 1 Introduction to Programming. Peter Schneider-Kamp. DM536 / DM550 Part 1 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk! http://imada.sdu.dk/~petersk/dm536/! CALLING FUNCTIONS 2 Calling Functions so far we have seen three different

More information

CUDA Toolkit 5.0 Performance Report. January 2013

CUDA Toolkit 5.0 Performance Report. January 2013 CUDA Toolkit 5.0 Performance Report January 2013 CUDA Math Libraries High performance math routines for your applications: cufft Fast Fourier Transforms Library cublas Complete BLAS Library cusparse Sparse

More information

Module 01: Introduction to Programming in Python

Module 01: Introduction to Programming in Python Module 01: Introduction to Programming in Python Topics: Course Introduction Introduction to Python basics Readings: ThinkP 1,2,3 1 Finding course information https://www.student.cs.uwaterloo.ca/~cs116/

More information

Script started on Thu 25 Aug :00:40 PM CDT

Script started on Thu 25 Aug :00:40 PM CDT Script started on Thu 25 Aug 2016 02:00:40 PM CDT < M A T L A B (R) > Copyright 1984-2014 The MathWorks, Inc. R2014a (8.3.0.532) 64-bit (glnxa64) February 11, 2014 To get started, type one of these: helpwin,

More information

Statistical Data Analysis: Python Tutorial

Statistical Data Analysis: Python Tutorial 1 October 4, 2017 Statistical Data Analysis: Python Tutorial Dr A. J. Bevan, Contents 1 Getting started 1 2 Basic calculations 2 3 More advanced calculations 4 4 Data sets 5 4.1 CSV file input.............................................

More information

MTH 337 Introduction to Scientific and Mathematical Computing. Fall Instructor: Adam Cunningham University at Buffalo Department of Mathematics

MTH 337 Introduction to Scientific and Mathematical Computing. Fall Instructor: Adam Cunningham University at Buffalo Department of Mathematics MTH 337 Introduction to Scientific and Mathematical Computing Fall 2015 Instructor: Adam Cunningham University at Buffalo Department of Mathematics Contents 1 Getting Started 4 1.1 Course Description.....................................

More information

The Cygnus C Math Library

The Cygnus C Math Library The Cygnus C Math Library libm 1.4 December 1995 Steve Chamberlain Roland Pesch Cygnus Support Cygnus Support sac@cygnus.com pesch@cygnus.com Copyright c 1992, 1993 Cygnus Support libm includes software

More information

The Red Hat newlib C Math Library

The Red Hat newlib C Math Library The Red Hat newlib C Math Library libm 1.17.0 December 2008 Steve Chamberlain Roland Pesch Red Hat Support Jeff Johnston Red Hat Support sac@cygnus.com pesch@cygnus.com jjohnstn@redhat.com Copyright c

More information

S III. Case Study: TI Calculator Numerics

S III. Case Study: TI Calculator Numerics Introduction S III. Case Study: TI Calculator Numerics Texas Instruments started a research project in 1965 to design a pocket calculator. The first pocket calculators appeared in the early 1970 from the

More information

The Red Hat newlib C Math Library

The Red Hat newlib C Math Library The Red Hat newlib C Math Library libm 1.11.0 July 2002 Steve Chamberlain Roland Pesch Red Hat Support Jeff Johnston Red Hat Support sac@cygnus.com pesch@cygnus.com jjohnstn@redhat.com Copyright c 1992,

More information

Lab 3: for and while Loops, Indexing. Ling 1330/2330: Computational Linguistics Na-Rae Han

Lab 3: for and while Loops, Indexing. Ling 1330/2330: Computational Linguistics Na-Rae Han Lab 3: for and while Loops, Indexing Ling 1330/2330: Computational Linguistics Na-Rae Han Objectives Split vs. join Loops for loop while loop Indexing List and string indexing & slicing Tips How to program

More information

Lesson 4: Type Conversion, Mutability, Sequence Indexing. Fundamentals of Text Processing for Linguists Na-Rae Han

Lesson 4: Type Conversion, Mutability, Sequence Indexing. Fundamentals of Text Processing for Linguists Na-Rae Han Lesson 4: Type Conversion, Mutability, Sequence Indexing Fundamentals of Text Processing for Linguists Na-Rae Han Objectives Python data types Mutable vs. immutable object types How variable assignment

More information

Essentials for Scientific Computing: Introduction to Python Day 11 & 12

Essentials for Scientific Computing: Introduction to Python Day 11 & 12 Essentials for Scientific Computing: Introduction to Python Day 11 & 12 Ershaad Ahamed TUE-CMS, JNCASR May 2012 1 Conditionals 1.1 if Construct In python blocks of code are created by indentation. That

More information

PyCUDA. Continued...

PyCUDA. Continued... PyCUDA Continued... gpuarray Vector Types pycuda.gpuarray.vec All CUDA vector types are supported: float3, int3, long4, etc, Available as numpy data types Field names x, y, z, and w as in CUDA Construct

More information

Downloaded from Chapter 2. Functions

Downloaded from   Chapter 2. Functions Chapter 2 Functions After studying this lesson, students will be able to: Understand and apply the concept of module programming Write functions Identify and invoke appropriate predefined functions Create

More information

Lecture 6: A step back

Lecture 6: A step back Lecture 6: A step back Last time We introduced a scripting language known as Python -- We started with the barest of motivation in terms of historical context and then jumped right in, focusing mainly

More information

Introduction to GPGPUs and to CUDA programming model: CUDA Libraries

Introduction to GPGPUs and to CUDA programming model: CUDA Libraries Introduction to GPGPUs and to CUDA programming model: CUDA Libraries www.cineca.it Marzia Rivi m.rivi@cineca.it NVIDIA CUDA Libraries http://developer.nvidia.com/technologies/libraries CUDA Toolkit includes

More information

Python Lists: Example 1: >>> items=["apple", "orange",100,25.5] >>> items[0] 'apple' >>> 3*items[:2]

Python Lists: Example 1: >>> items=[apple, orange,100,25.5] >>> items[0] 'apple' >>> 3*items[:2] Python Lists: Lists are Python's compound data types. A list contains items separated by commas and enclosed within square brackets ([]). All the items belonging to a list can be of different data type.

More information

CUDA Toolkit 4.0 Performance Report. June, 2011

CUDA Toolkit 4.0 Performance Report. June, 2011 CUDA Toolkit 4. Performance Report June, 211 CUDA Math Libraries High performance math routines for your applications: cufft Fast Fourier Transforms Library cublas Complete BLAS Library cusparse Sparse

More information

tag 220 tan[f l] struct { int i; double d; } sa, sb; struct { int i; double d; } s1, s2;

tag 220 tan[f l] struct { int i; double d; } sa, sb; struct { int i; double d; } s1, s2; tag 220 T tag The identifier that may optionally follow the keyword struct, union, or enum in a structure, union, or enumerated type definition, respectively. The tag is used later to refer to that particular

More information

Data Parallel Execution Model

Data Parallel Execution Model CS/EE 217 GPU Architecture and Parallel Programming Lecture 3: Kernel-Based Data Parallel Execution Model David Kirk/NVIDIA and Wen-mei Hwu, 2007-2013 Objective To understand the organization and scheduling

More information

SAMPLE CHAPTER. Naomi Ceder MANNING. Foreword by Nicholas Tollervey

SAMPLE CHAPTER. Naomi Ceder MANNING. Foreword by Nicholas Tollervey SAMPLE CHAPTER Naomi Ceder Foreword by Nicholas Tollervey MANNING The Quick Python Book Third Edition by Naomi Ceder Sample Chapter 4 Copyright 2018 Manning Publications brief contents PART 1 STARTING

More information

Variable and Data Type 2

Variable and Data Type 2 The Islamic University of Gaza Faculty of Engineering Dept. of Computer Engineering Intro. To Computers (LNGG 1003) Lab 3 Variable and Data Type 2 Eng. Ibraheem Lubbad March 2, 2017 Python Lists: Lists

More information

OpenCL Overview. Tim Mattson Intel Labs. Copyright Khronos Group, Page 1

OpenCL Overview. Tim Mattson Intel Labs. Copyright Khronos Group, Page 1 OpenCL Overview Tim Mattson Intel Labs Copyright Khronos Group, 2009 - Page 1 Programming Heterogeneous Platforms CPUs Multiple cores driving performance increases Emerging Intersection GPUs Increasingly

More information

Introduction to MATLAB

Introduction to MATLAB Outlines January 30, 2008 Outlines Part I: Part II: Writing MATLAB Functions Starting MATLAB Exiting MATLAB Getting Help Command Window Workspace Command History Current Directory Selector Real Values

More information

A. Matrix-wise and element-wise operations

A. Matrix-wise and element-wise operations USC GSBME MATLAB CLASS Reviewing previous session Second session A. Matrix-wise and element-wise operations A.1. Matrix-wise operations So far we learned how to define variables and how to extract data

More information

CUDA 6.0 Performance Report. April 2014

CUDA 6.0 Performance Report. April 2014 CUDA 6. Performance Report April 214 1 CUDA 6 Performance Report CUDART CUDA Runtime Library cufft Fast Fourier Transforms Library cublas Complete BLAS Library cusparse Sparse Matrix Library curand Random

More information

RETURN VALUE The acos() function returns the arc cosine in radians and the value is mathematically defined to be between 0 and PI (inclusive).

RETURN VALUE The acos() function returns the arc cosine in radians and the value is mathematically defined to be between 0 and PI (inclusive). ACOS(3) Linux Programmer s Manual ACOS(3) acos, acosf, acosl arc cosine function double acos(double x); float acosf(float x); long double acosl(long double x); The acos() function calculates the arc cosine

More information

Files on disk are organized hierarchically in directories (folders). We will first review some basics about working with them.

Files on disk are organized hierarchically in directories (folders). We will first review some basics about working with them. 1 z 9 Files Petr Pošík Department of Cybernetics, FEE CTU in Prague EECS, BE5B33PRG: Programming Essentials, 2015 Requirements: Loops Intro Information on a computer is stored in named chunks of data called

More information

Numeric Vectors STAT 133. Gaston Sanchez. Department of Statistics, UC Berkeley

Numeric Vectors STAT 133. Gaston Sanchez. Department of Statistics, UC Berkeley Numeric Vectors STAT 133 Gaston Sanchez Department of Statistics, UC Berkeley gastonsanchez.com github.com/gastonstat/stat133 Course web: gastonsanchez.com/stat133 Data Types and Structures To make the

More information

Mentor Graphics Predefined Packages

Mentor Graphics Predefined Packages Mentor Graphics Predefined Packages Mentor Graphics has created packages that define various types and subprograms that make it possible to write and simulate a VHDL model within the Mentor Graphics environment.

More information

Introduction to MATLAB

Introduction to MATLAB Outlines September 9, 2004 Outlines Part I: Review of Previous Lecture Part II: Part III: Writing MATLAB Functions Review of Previous Lecture Outlines Part I: Review of Previous Lecture Part II: Part III:

More information

An introduction to R WS 2013/2014

An introduction to R WS 2013/2014 An introduction to R WS 2013/2014 Dr. Noémie Becker (AG Metzler) Dr. Sonja Grath (AG Parsch) Special thanks to: Dr. Martin Hutzenthaler (previously AG Metzler, now University of Frankfurt) course development,

More information

Arithmetic and Logic Blocks

Arithmetic and Logic Blocks Arithmetic and Logic Blocks The Addition Block The block performs addition and subtractions on its inputs. This block can add or subtract scalar, vector, or matrix inputs. We can specify the operation

More information

Matlab Workshop I. Niloufer Mackey and Lixin Shen

Matlab Workshop I. Niloufer Mackey and Lixin Shen Matlab Workshop I Niloufer Mackey and Lixin Shen Western Michigan University/ Syracuse University Email: nil.mackey@wmich.edu, lshen03@syr.edu@wmich.edu p.1/13 What is Matlab? Matlab is a commercial Matrix

More information

CS-201 Introduction to Programming with Java

CS-201 Introduction to Programming with Java CS-201 Introduction to Programming with Java California State University, Los Angeles Computer Science Department Lecture V: Mathematical Functions, Characters, and Strings Introduction How would you estimate

More information

6-1 (Function). (Function) !*+!"#!, Function Description Example. natural logarithm of x (base e) rounds x to smallest integer not less than x

6-1 (Function). (Function) !*+!#!, Function Description Example. natural logarithm of x (base e) rounds x to smallest integer not less than x (Function) -1.1 Math Library Function!"#! $%&!'(#) preprocessor directive #include !*+!"#!, Function Description Example sqrt(x) square root of x sqrt(900.0) is 30.0 sqrt(9.0) is 3.0 exp(x) log(x)

More information

LAB 1 General MATLAB Information 1

LAB 1 General MATLAB Information 1 LAB 1 General MATLAB Information 1 General: To enter a matrix: > type the entries between square brackets, [...] > enter it by rows with elements separated by a space or comma > rows are terminated by

More information

13Holzner_index.qxd 3/23/05 1:51 PM Page 331. Index

13Holzner_index.qxd 3/23/05 1:51 PM Page 331. Index 13Holzner_index.qxd 3/23/05 1:51 PM Page 331 Index Symbols * (asterisks), 152 * (multiplication), 34 + (addition), 34 ++, 38-39 +=, 37 - (subtraction), 34, 38-39. (concatenation operator), 43 = (equal

More information

Com S 127 Lab 2. For the first two parts of the lab, start up Wing 101 and use the Python shell window to try everything out.

Com S 127 Lab 2. For the first two parts of the lab, start up Wing 101 and use the Python shell window to try everything out. Com S 127 Lab 2 Checkpoint 0 Please open the CS 127 Blackboard page and click on Groups in the menu at left. Sign up for the group corresponding to the lab section you are attending. Also, if you haven't

More information

examples from first year calculus (continued), file I/O, Benford s Law

examples from first year calculus (continued), file I/O, Benford s Law examples from first year calculus (continued), file I/O, Benford s Law Matt Valeriote 5 February 2018 Grid and Bisection methods to find a root Assume that f (x) is a continuous function on the real numbers.

More information

CSE 591: GPU Programming. Programmer Interface. Klaus Mueller. Computer Science Department Stony Brook University

CSE 591: GPU Programming. Programmer Interface. Klaus Mueller. Computer Science Department Stony Brook University CSE 591: GPU Programming Programmer Interface Klaus Mueller Computer Science Department Stony Brook University Compute Levels Encodes the hardware capability of a GPU card newer cards have higher compute

More information

The float type and more on variables FEB 6 TH 2012

The float type and more on variables FEB 6 TH 2012 The float type and more on variables FEB 6 TH 2012 The float type Numbers with decimal points are easily represented in binary: 0.56 (in decimal) = 5/10 + 6/100 0.1011 (in binary) = ½+0/4 + 1/8 +1/16 The

More information

Package Brobdingnag. R topics documented: March 19, 2018

Package Brobdingnag. R topics documented: March 19, 2018 Type Package Title Very Large Numbers in R Version 1.2-5 Date 2018-03-19 Author Depends R (>= 2.13.0), methods Package Brobdingnag March 19, 2018 Maintainer Handles very large

More information

CS1110 Lab 6 (Mar 17-18, 2015)

CS1110 Lab 6 (Mar 17-18, 2015) CS1110 Lab 6 (Mar 17-18, 2015) First Name: Last Name: NetID: The lab assignments are very important and you must have a CS 1110 course consultant tell CMS that you did the work. (Correctness does not matter.)

More information

Highly Optimized Mathematical Functions for the Itanium Processor

Highly Optimized Mathematical Functions for the Itanium Processor Highly Optimized Mathematical Functions for the Itanium Processor! Speaker: Shane Story! Software Engineer! CSL Numerics Group! Corporation Copyright Copyright 2001 2001 Corporation. Agenda! Itanium Processor

More information

Description/History Objects/Language Description Commonly Used Basic Functions. More Specific Functionality Further Resources

Description/History Objects/Language Description Commonly Used Basic Functions. More Specific Functionality Further Resources R Outline Description/History Objects/Language Description Commonly Used Basic Functions Basic Stats and distributions I/O Plotting Programming More Specific Functionality Further Resources www.r-project.org

More information

Introduction to GNU-Octave

Introduction to GNU-Octave Introduction to GNU-Octave Dr. K.R. Chowdhary, Professor & Campus Director, JIETCOE JIET College of Engineering Email: kr.chowdhary@jietjodhpur.ac.in Web-Page: http://www.krchowdhary.com July 11, 2016

More information

File I/O, Benford s Law, and sets

File I/O, Benford s Law, and sets File I/O, Benford s Law, and sets Matt Valeriote 11 February 2019 Benford s law Benford s law describes the (surprising) distribution of first digits of many different sets of numbers. Read it about it

More information

Introduction to Matlab. Matlab variable types. Matlab variable types. Matlab variable types. Notes. Eugeniy E. Mikhailov. Lecture 02. Notes.

Introduction to Matlab. Matlab variable types. Matlab variable types. Matlab variable types. Notes. Eugeniy E. Mikhailov. Lecture 02. Notes. Introduction to Matlab Eugeniy E. Mikhailov The College of William & Mary Lecture 02 Eugeniy Mikhailov (W&M) Practical Computing Lecture 02 1 / 26 Matlab variable types Eugeniy Mikhailov (W&M) Practical

More information

Introduction to Python

Introduction to Python Introduction to Python Efstratios RAPPOS efstratios.rappos@heig-vd.ch Slide 1 2016 HEIG-VD SNU Summer School Background Easy and popular programming language Interpreted: must have python installed to

More information

Computational Physics

Computational Physics Computational Physics Python Programming Basics Prof. Paul Eugenio Department of Physics Florida State University Jan 17, 2019 http://hadron.physics.fsu.edu/~eugenio/comphy/ Announcements Exercise 0 due

More information

Some elements for Matlab programming

Some elements for Matlab programming Some elements for Matlab programming Nathalie Thomas 2018 2019 Matlab, which stands for the abbreviation of MATrix LABoratory, is one of the most popular language for scientic computation. The classical

More information

Chapter 3 : Computer Science. Class XI ( As per CBSE Board) Data Handling. Visit : python.mykvs.in for regular updates

Chapter 3 : Computer Science. Class XI ( As per CBSE Board) Data Handling. Visit : python.mykvs.in for regular updates Chapter 3 : Computer Science Class XI ( As per CBSE Board) Data Handling Introduction Most of the computer programming language support data type, variables,operator and expression like fundamentals.python

More information

STA141C: Big Data & High Performance Statistical Computing

STA141C: Big Data & High Performance Statistical Computing STA141C: Big Data & High Performance Statistical Computing Lecture 1: Python programming (1) Cho-Jui Hsieh UC Davis April 4, 2017 Python Python is a scripting language: Non-scripting language (C++. java):

More information

Lecture 8 Mathematics

Lecture 8 Mathematics CS 491 CAP Intro to Competitive Algorithmic Programming Lecture 8 Mathematics Uttam Thakore University of Illinois at Urbana-Champaign October 14, 2015 Outline Number theory Combinatorics & probability

More information

TS Calc 1.6 User Guide

TS Calc 1.6 User Guide ! TS Calc 1.6 User Guide We Make Software - TensionSoftware.com TS Calc 2009-2018 Tension Software all rights reserved Every effort has been made to ensure that the information in this manual is accurate.

More information

Lab 12: Processing a Corpus. Ling 1330/2330: Computational Linguistics Na-Rae Han

Lab 12: Processing a Corpus. Ling 1330/2330: Computational Linguistics Na-Rae Han Lab 12: Processing a Corpus Ling 1330/2330: Computational Linguistics Na-Rae Han Objectives How to process a corpus 10/4/2018 2 Beyond a single, short text So far, we have been handling relatively short

More information

DSC 201: Data Analysis & Visualization

DSC 201: Data Analysis & Visualization DSC 201: Data Analysis & Visualization Arrays and Series Dr. David Koop Exception Example def divide(mylist, x,y): newlist = [] try: z = x // y below, mid, above = \ mylist[:z], mylist[z], mylist[z+1:]

More information

Outline. Introduction Intel Vector Math Library (VML) o Features and performance VML in Finance Useful links

Outline. Introduction Intel Vector Math Library (VML) o Features and performance VML in Finance Useful links Outline Introduction Intel Vector Math Library (VML) o Features and performance VML in Finance Useful links 2 Introduction VML is one component of Intel MKL Support HPC applications: o o Scientific & engineering

More information

Introduction To Python

Introduction To Python Introduction To Python Week 5: Finish up I/O On To Functions Dr. Jim Lupo Asst Dir Computational Enablement LSU Center for Computation & Technology 18 Jun 2015, Page 1 of 31 I/O - Continued Revisit the

More information

By the end of this section of the practical, the students should be able to:

By the end of this section of the practical, the students should be able to: By the end of this section of the practical, the students should be able to: Write JavaScript to generate HTML Create simple scripts which include input and output statements, arithmetic, relational and

More information

Introduction to Scientific and Engineering Computing, BIL108E. Karaman

Introduction to Scientific and Engineering Computing, BIL108E. Karaman USING MATLAB INTRODUCTION TO SCIENTIFIC & ENGINEERING COMPUTING BIL 108E, CRN24023 To start from Windows, Double click the Matlab icon. To start from UNIX, Dr. S. Gökhan type matlab at the shell prompt.

More information

Single row numeric functions

Single row numeric functions Single row numeric functions Oracle provides a lot of standard numeric functions for single rows. Here is a list of all the single row numeric functions (in version 10.2). Function Description ABS(n) ABS

More information

MATLAB and Numerical Analysis

MATLAB and Numerical Analysis School of Mechanical Engineering Pusan National University dongwoonkim@pusan.ac.kr Teaching Assistant 김동운 dongwoonkim@pusan.ac.kr 윤종희 jongheeyun@pusan.ac.kr Lab office: 통합기계관 120호 ( 510-3921) 방사선영상연구실홈페이지

More information

Variables. location where in memory is the information stored type what sort of information is stored in that memory

Variables. location where in memory is the information stored type what sort of information is stored in that memory Variables Processing, like many programming languages, uses variables to store information Variables are stored in computer memory with certain attributes location where in memory is the information stored

More information

CSI31 Lecture 5. Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial

CSI31 Lecture 5. Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial CSI31 Lecture 5 Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial 1 3.1 Numberic Data Types When computers were first developed, they were seen primarily as

More information

DSC 201: Data Analysis & Visualization

DSC 201: Data Analysis & Visualization DSC 201: Data Analysis & Visualization Classes & Arrays Dr. David Koop Sets Sets are like dictionaries but without any values: s = {'MA', 'RI', 'CT', 'NH'}; t = {'MA', 'NY', 'NH'} {} is an empty dictionary,

More information

Object-Based Programming. Programming with Objects

Object-Based Programming. Programming with Objects ITEC1620 Object-Based Programming g Lecture 8 Programming with Objects Review Sequence, Branching, Looping Primitive datatypes Mathematical operations Four-function calculator Scientific calculator Don

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab Eugeniy E. Mikhailov The College of William & Mary Lecture 02 Eugeniy Mikhailov (W&M) Practical Computing Lecture 02 1 / 27 Matlab variable types Eugeniy Mikhailov (W&M) Practical

More information

Objectives. You will learn how to process data in ABAP

Objectives. You will learn how to process data in ABAP Objectives You will learn how to process data in ABAP Assigning Values Resetting Values to Initial Values Numerical Operations Processing Character Strings Specifying Offset Values for Data Objects Type

More information

Introduction to MATLAB for CSE390

Introduction to MATLAB for CSE390 Introduction Introduction to MATLAB for CSE390 Professor Vijay Kumar Praveen Srinivasan University of Pennsylvania MATLAB is an interactive program designed for scientific computations, visualization and

More information

Introduction to Programming

Introduction to Programming Introduction to Programming session 9 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2010 These slides are created using Deitel s slides Sahrif University of Technology Outlines

More information

ECET 264 C Programming Language with Applications

ECET 264 C Programming Language with Applications ECET 264 C Programming Language with Applications Lecture 10 C Standard Library Functions Paul I. Lin Professor of Electrical & Computer Engineering Technology http://www.etcs.ipfw.edu/~lin Lecture 10

More information

Introduction to Computer Programming in Python Dr. William C. Bulko. Data Types

Introduction to Computer Programming in Python Dr. William C. Bulko. Data Types Introduction to Computer Programming in Python Dr William C Bulko Data Types 2017 What is a data type? A data type is the kind of value represented by a constant or stored by a variable So far, you have

More information

7. MODULES. Rocky K. C. Chang October 17, (Based on Dierbach)

7. MODULES. Rocky K. C. Chang October 17, (Based on Dierbach) 7. MODULES Rocky K. C. Chang October 17, 2016 (Based on Dierbach) Objectives Explain the specification of modules. Become familiar with the use of docstrings in Python. Explain the use of modules and namespaces

More information

The Red Hat newlib C Math Library

The Red Hat newlib C Math Library The Red Hat newlib C Math Library libm 2.1.0 December 2013 Steve Chamberlain Roland Pesch Red Hat Support Jeff Johnston Red Hat Support sac@cygnus.com pesch@cygnus.com jjohnstn@redhat.com Copyright c 1992,

More information

Lecture 3: Functions & Modules (Sections ) CS 1110 Introduction to Computing Using Python

Lecture 3: Functions & Modules (Sections ) CS 1110 Introduction to Computing Using Python http://www.cs.cornell.edu/courses/cs1110/2019sp Lecture 3: Functions & Modules (Sections 3.1-3.3) CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner,

More information

Python BASICS. Introduction to Python programming, basic concepts: formatting, naming conventions, variables, etc.

Python BASICS. Introduction to Python programming, basic concepts: formatting, naming conventions, variables, etc. Python BASICS Introduction to Python programming, basic concepts: formatting, naming conventions, variables, etc. Identikit First appeared in 1991 Designed by Guido van Rossum General purpose High level

More information

NLP Lab Session Week 4 September 17, Reading and Processing Test, Stemming and Lemmatization. Getting Started

NLP Lab Session Week 4 September 17, Reading and Processing Test, Stemming and Lemmatization. Getting Started NLP Lab Session Week 4 September 17, 2014 Reading and Processing Test, Stemming and Lemmatization Getting Started In this lab session, we will use two saved files of python commands and definitions and

More information

ELEMENTARY MATLAB PROGRAMMING

ELEMENTARY MATLAB PROGRAMMING 1 ELEMENTARY MATLAB PROGRAMMING (Version R2013a used here so some differences may be encountered) COPYRIGHT Irving K. Robbins 1992, 1998, 2014, 2015 All rights reserved INTRODUCTION % It is assumed the

More information

INSIDE MACINTOSH. Addison-Wesley Publishing Company

INSIDE MACINTOSH. Addison-Wesley Publishing Company apple INSIDE MACINTOSH PowerPC Numerics Addison-Wesley Publishing Company Reading, Massachusetts Menlo Park, California New York Don Mills, Ontario Wokingham, England Amsterdam Bonn Sydney Singapore Tokyo

More information

Basic types and definitions. Chapter 3 of Thompson

Basic types and definitions. Chapter 3 of Thompson Basic types and definitions Chapter 3 of Thompson Booleans [named after logician George Boole] Boolean values True and False are the result of tests are two numbers equal is one smaller than the other

More information

Starting MATLAB To logon onto a Temple workstation at the Tech Center, follow the directions below.

Starting MATLAB To logon onto a Temple workstation at the Tech Center, follow the directions below. What is MATLAB? MATLAB (short for MATrix LABoratory) is a language for technical computing, developed by The Mathworks, Inc. (A matrix is a rectangular array or table of usually numerical values.) MATLAB

More information

CPSC 217 Midterm (Python 3 version)

CPSC 217 Midterm (Python 3 version) CPSC 217 Midterm (Python 3 version) Duration: 50 minutes 6 March 2009 This exam has 61 questions and 11 pages. This exam is closed book. No notes, books, calculators or electronic devices, or other assistance

More information

Computer Science 121. Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans

Computer Science 121. Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans Computer Science 121 Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans 3.1 The Organization of Computer Memory Computers store information as bits : sequences of zeros and

More information