1 | Text of the question | Hint | Answer | |
---|---|---|---|---|
2 | 1 | A very common need is to display a 3D graph of Jedi master Yoda on the web. What kind of tool can be used to accomplish this? | Mathematical software written in Python | Sage (http://www.sagemath.org/) |
3 | 2 | let variable a be one dimensional array with 10 elements. What does a.shape=(3,4) do? or a.shape=(3,3)? what are the values of a[2,2] and a[2,3] ? | slide nr 34 | this will result in an error Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: total size of new array must be unchanged |
4 | 3 | It's possible to generate a lower complexity than O(n^3) for multiply two matrices? | Slide 55 Link: http://www.syntagmatic.net/matrix-multiplication-in-python/ | yes, it is possible NumPy implements a function that enables to reduce such complexity to O(k), where 2<k<3 |
5 | 4 | Is it possible to install SciPy without ATLAS? | http://cens.ioc.ee/~pearu/scipy/INSTALL.html | Yes! If you're willing to sacrifice some performance (5-15 in case of some large computing problem) and you really don't like ATLAS, you can install SciPy without it. However, you'll still need Fortran LAPACK/BLAS libraries in your system or their sources to be accessible for SciPy install scripts. |
6 | 5 | What do NumPy and SciPy extensions add to Python programming language? | http://www.scipy.org/Getting_Started http://en.wikipedia.org/wiki/NumPy | NumPy adds support for numerical multi-dimensional arrays and matrices, and provides basic operations on them. SciPy add more functionality for processing arrays and matrices: advanced math (e.g. integration), signal processing, optimization, statistics. |
7 | 6 | Why are array operations in NumPy faster than element-wise operations? | http://www.scipy.org/Getting_Started | NumPy saves time, because some loops are not needed. Some operations like type check are done only once for NumPy arrays (but every loop iteration in usual Python) |
8 | 7 | a = array([1,2,3,4]) b = array([[1,2],[3,4]]) c = array([[[1],[2]],[[3],[4]]]) Which operations are right? 1) mat(a) 2) matrix(b) 3) mat(c) 4) matrix(c) | slides 22-23 | 1 and 2 c is 3-dimensional array, it can't be converted to matrix. mat() and matrix() are synonymous |
9 | 8 | Slide 55: >>>x1 = array([1,2,3], float) >>>x2 = matrix(x) Should it be >>>x2 = matrix(x1) ? | slide 55 | Yes, there was a typo on the slide! |
10 | 9 | What is vectorization of a function? | slides 57-64 | It is an adaption of function to be used not only for scalar, but also for an array. |
11 | 10 | Name 3 or more linear algebra capabilities that NumPy has. | Slide 67 | Solving linear systems, computing determinant of a matrix and an inverse of a matrix, computing eigenvalues and eigenvectors of a matrix, solving least-squares problems. |
12 | 11 | array a is ([ 1., 10., -2., 4., 5., -2., 10., 10.]) What happens to the array when the following command it executed: a[a > 0] = a.min() | slide 38 | ([ -2., -2., -2., -2., -2., -2., -2., -2.]) |
13 | 12 | If a is an array, what does this command do? a **= 4.5 | slide 44 | Every element in the array a is put to the power of 4.5 |
14 | 13 | Let's go deeper into copying objects. Say you have a list that contains lists: a = [1,2,[3,4]] You now try to make a copy: b = a[:] Or in another way: from copy import copy c = copy(a) Now you change b and c: b[0] = 9 b[2][0] = 5 c[1] = 8 c[2][1] = 6 What are the contents of a, b and c? How can you make a copy of a so that when you change the copy, the original isn't affected? | http://docs.python.org/py3k/library/copy.html http://www.python-course.eu/deep_copy.php | a = [1,2,[5,6]] b = [9,2,[5,6]] c = [1,8,[5,6]] [:] and copy() make a copy of an object so that if the object contains other objects, for these only references are copied. You can make a copy of everything by using deepcopy: from copy import deepcopy d = deepcopy(a) ... |
15 | 14 | When to use a Fortran implementation in python? | 1 Lecture, Slide 20 | An application manipulates with large data set and speed has become a critical factor. |
16 | 15 | What kind of advantage is from floating-point representation? | http://en.wikipedia.org/wiki/Floating_point | The advantage of floating-point representation over fixed-point and integer representation is that it can support a much wider range of values. For example, a fixed-point representation that has seven decimal digits with two decimal places can represent the numbers 12345.67, 123.45, 1.23 and so on, whereas a floating-point representation (such as the IEEE 754 decimal32 format) with seven decimal digits could in addition represent 1.234567, 123456.7, 0.00001234567, 1234567000000000, and so on. |
17 | 16 | How to generate random array with NxN dimensions? | e=np.random.randint(1,7,(N*N)) ps=np.array(e, dtype=float).reshape(N,N) | |
18 | 17 | Why is better to use arrays operations instead of standard lops? | Slide 56 | Lops are slower in case of an efficiency is required |
19 | 18 | what is the effect of [:] on a list? | Slide 36 | A copy is made |
20 | 19 | what is the effect of [:] on an array? | Slide 36 | A reference is made |
21 | 20 | what is the effect of a.copy() on an array "a"? | Slide 36 | A copy is made |
22 | 21 | What might be the reasons for using arithmetic operations with arrays as opposed to element-wise operations? | Slide 42 | Faster operations Simpler to perform some tasks Less programming overhead |
23 | 22 | How should an array 'arr' of length x with initial values i be created in Python? | Slide 48 | arr = zeros(x) + i |
24 | 23 | What is a direct method? | http://en.wikipedia.org/wiki/Numerical_analysis | Direct methods compute the solution to a problem in a finite number of steps. These methods would give the precise answer if they were performed in infinite precision arithmetic. Examples include Gaussian elimination, the QR factorization method for solving systems of linear equations, and the simplex method of linear programming. In practice, finite precision is used and the result is an approximation of the true solution (assuming stability). |