In [1]:
import numpy as np
In [2]:
x = np.ones(5)
In [3]:
x
Out[3]:
array([1., 1., 1., 1., 1.])
In [4]:
print(x)
[1. 1. 1. 1. 1.]
In [5]:
def f(x):
    return 2+x
In [6]:
f
Out[6]:
<function __main__.f>
In [7]:
print(f)
<function f at 0x7f8834126598>
In [8]:
repr(f)
Out[8]:
'<function f at 0x7f8834126598>'
In [9]:
repr(x)
Out[9]:
'array([1., 1., 1., 1., 1.])'
In [10]:
str(x)
Out[10]:
'[1. 1. 1. 1. 1.]'
In [11]:
str(f)
Out[11]:
'<function f at 0x7f8834126598>'
In [12]:
print(x)
[1. 1. 1. 1. 1.]
In [14]:
x.__str__()
Out[14]:
'[1. 1. 1. 1. 1.]'
In [15]:
x.__repr__()
Out[15]:
'array([1., 1., 1., 1., 1.])'
In [16]:
import sympy as sm
In [17]:
x, y = sm.symbols('x, y')
In [18]:
x
Out[18]:
$\displaystyle x$
In [19]:
x + y
Out[19]:
$\displaystyle x + y$
In [20]:
repr(x)
Out[20]:
'x'
In [21]:
repr(x + y)
Out[21]:
'x + y'
In [22]:
str(x + y)
Out[22]:
'x + y'
In [23]:
x = np.ones((2, 2))
In [24]:
x
Out[24]:
array([[1., 1.],
       [1., 1.]])
In [25]:
x[0, 0]
Out[25]:
1.0
In [26]:
a = [1, 2, 3]
type(a)
Out[26]:
list
In [27]:
a
Out[27]:
[1, 2, 3]
In [28]:
y = ['a', 1, 9.0]
In [29]:
y
Out[29]:
['a', 1, 9.0]
In [30]:
import numpy as np
In [31]:
np.array(y)
Out[31]:
array(['a', '1', '9.0'], dtype='<U3')
In [34]:
my_list = []
for i in range(20):
    print(i)
    my_list.append(i**2)
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
In [35]:
my_list
Out[35]:
[0,
 1,
 4,
 9,
 16,
 25,
 36,
 49,
 64,
 81,
 100,
 121,
 144,
 169,
 196,
 225,
 256,
 289,
 324,
 361]
In [36]:
my_array = np.array(my_list)
In [37]:
my_array
Out[37]:
array([  0,   1,   4,   9,  16,  25,  36,  49,  64,  81, 100, 121, 144,
       169, 196, 225, 256, 289, 324, 361])
In [38]:
my_list * 2
Out[38]:
[0,
 1,
 4,
 9,
 16,
 25,
 36,
 49,
 64,
 81,
 100,
 121,
 144,
 169,
 196,
 225,
 256,
 289,
 324,
 361,
 0,
 1,
 4,
 9,
 16,
 25,
 36,
 49,
 64,
 81,
 100,
 121,
 144,
 169,
 196,
 225,
 256,
 289,
 324,
 361]
In [39]:
my_array * 2
Out[39]:
array([  0,   2,   8,  18,  32,  50,  72,  98, 128, 162, 200, 242, 288,
       338, 392, 450, 512, 578, 648, 722])
In [40]:
np.random.random(5)
Out[40]:
array([0.64327535, 0.64564919, 0.78193309, 0.03636536, 0.37608049])
In [41]:
a = np.random.random(5)
b = np.random.random(5)
In [42]:
a
Out[42]:
array([0.83327995, 0.2396199 , 0.74695168, 0.06965017, 0.39579413])
In [43]:
b
Out[43]:
array([0.42479002, 0.95725464, 0.4073338 , 0.30301574, 0.3486592 ])
In [45]:
np.sqrt(a**2 + b**2)
Out[45]:
array([0.93530852, 0.98678982, 0.85079823, 0.31091749, 0.52746206])
In [46]:
for thing in ['a', 'b', 'c']:
    print(thing)
a
b
c
In [47]:
for i, thing in enumerate(['a', 'b', 'c']):
    print(i)
    print(thing)
0
a
1
b
2
c
In [1]:
from utils2 import period2freq, freq2period
In [2]:
period2freq(5.0)
Out[2]:
1.2566370614359172
In [3]:
period2freq?
Signature: period2freq(period)
Docstring: Returns frequency in rad/s given period in seconds.
File:      ~/eng122-2020w-notebook-02/utils2.py
Type:      function
In [ ]: