There isn't much point to doing a simple

`import scipy`

This package is switching to an array interface, compatible with NumPy arrays, from the older matrix interface. We recommend that you use the array objects (bsr_array, coo_array, etc.) for all new work.,As of NumPy 1.7, np.dot is not aware of sparse matrices, therefore using it will result on unexpected results or errors. The corresponding dense array should be obtained first instead:,x * y no longer performs matrix multiplication, but element-wise multiplication (just like with NumPy arrays). To make code work with both arrays and matrices, use x @ y for matrix multiplication.,Sparse arrays currently must be two-dimensional. This also means that all slicing operations on these objects must produce two-dimensional results, or they will result in an error. This will be addressed in a future version.

A = csr_array(eye(3))

```
>>>
import numpy as np
>>>
from scipy.sparse
import csr_matrix
>>>
A = csr_matrix([
[1, 2, 0],
[0, 0, 3],
[4, 0, 5]
]) >>>
v = np.array([1, 0, -1]) >>>
A.dot(v)
array([1, -3, -1], dtype = int64)
```

>>> np.dot(A.toarray(), v) array([1, -3, -1], dtype = int64)

```
>>> from scipy.sparse
import lil_matrix
>>>
from scipy.sparse.linalg
import spsolve
>>>
from numpy.linalg
import solve, norm
>>>
from numpy.random
import rand
```

>>> A = lil_matrix((1000, 1000)) >>> A[0,: 100] = rand(100) >>> A[1, 100: 200] = A[0,: 100] >>> A.setdiag(rand(1000))

>>> A = A.tocsr() >>> b = rand(1000) >>> x = spsolve(A, b)

Step 4: Now install the library using pip install scipy command. Here’s an analogous example:,If an import statement cannot import a module, it raises an ImportError. This may occur because of a faulty installation or an invalid path. In Python 3.6 or newer, this will usually raise a ModuleNotFoundError.,This is supposed to import the Pandas library into your (virtual) environment. However, it only throws the following ImportError: No module named scipy:,Quick Fix: Python raises the ImportError: No module named 'scipy' when it cannot find the library scipy. The most frequent source of this error is that you haven’t installed scipy explicitly with pip install scipy. Alternatively, you may have different Python versions on your computer, and scipy is not installed for the particular version you’re using.

You’ve just learned about the awesome capabilities of the `scipy`

library and you want to try it out, so you start your code with the following statement:

`import scipy`

This is supposed to import the Pandas library into your (virtual) environment. However, it only throws the following `ImportError: No module named scipy`

:

```
>>> import scipy
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
import scipy
ModuleNotFoundError: No module named 'scipy'
```

To fix this error, you can run the following command in your Windows shell:

$ pip install scipy

## Understanding the “import” Statement

`import scipy`

You can also check this relationship using the `issubclass()`

built-in function:

>>> issubclass(ModuleNotFoundError, ImportError) True

Explicit definitions of which portions of the signal are suitable for analysis (in oscillatory bursts) or not (no oscillation present).,Because of this last property, these traces have come to be known as “instantaneous amplitude” and “instantaneous phase.” And they seem to make a lot of sense, when looking at the raw signal.,As the most prominent feature of these signals tends to be the oscillations in them, spectral analysis is often applied in order to characterize these rhythms in terms of their frequency, power, and phase.,However, there are some key disadvantages to this analysis that stem from its sine wave basis.

import numpy as np import scipy as sp from scipy import signal as spsignal import matplotlib.pyplot as plt from bycycle.filt import amp_by_time, phase_by_time, bandpass_filter signal = np.load('data/sim_bursting_more_noise.npy') Fs = 1000 # Sampling rate f_alpha = (8, 12) N_seconds_filter = .5 # Compute amplitude and phase signal_filt = bandpass_filter(signal, Fs, f_alpha, N_seconds = N_seconds_filter) theta_amp = amp_by_time(signal, Fs, f_alpha, filter_kwargs = { 'N_seconds': N_seconds_filter }) theta_phase = phase_by_time(signal, Fs, f_alpha, filter_kwargs = { 'N_seconds': N_seconds_filter }) # Plots signal t = np.arange(0, len(signal) / Fs, 1 / Fs) tlim = (2, 6) tidx = np.logical_and(t >= tlim[0], t < tlim[1]) plt.figure(figsize = (12, 6)) plt.subplot(3, 1, 1) plt.plot(t[tidx], signal[tidx], 'k') plt.xlim(tlim) plt.ylabel('Voltage (mV)') plt.subplot(3, 1, 2) plt.plot(t[tidx], signal_filt[tidx], 'k', alpha = .5) plt.plot(t[tidx], theta_amp[tidx], 'r') plt.xlim(tlim) plt.ylabel('Oscillation amplitude', color = 'r') plt.subplot(3, 1, 3) plt.plot(t[tidx], theta_phase[tidx], 'r') plt.xlim(tlim) plt.ylabel('Phase (radians)', color = 'r') plt.tight_layout() plt.show()

```
/home/rph / Projects / bycycle / tutorials / plot_1_bycycle_philosophy.py: 65: UserWarning: Matplotlib is currently using agg, which is a non - GUI backend, so cannot show the figure.
plt.show()
```

# Different hyperparameter choices - filter length and center frequency and bandwidth f_alphas = [(6, 14), (8, 12), (9, 13)] N_secondss = [.4, .75, 1.2] amps = [] phases = [] for f_alpha in f_alphas: for N_seconds_filter in N_secondss: amp = amp_by_time(signal, Fs, f_alpha, filter_kwargs = { 'N_seconds': N_seconds_filter }) phase = phase_by_time(signal, Fs, f_alpha, filter_kwargs = { 'N_seconds': N_seconds_filter }) amps.append(amp) phases.append(phase) plt.figure(figsize = (12, 2)) for amp in amps: plt.plot(t[tidx], amp[tidx]) plt.xlim(tlim) plt.tight_layout() plt.show()

```
/home/rph / Projects / bycycle / tutorials / plot_1_bycycle_philosophy.py: 122: UserWarning: Matplotlib is currently using agg, which is a non - GUI backend, so cannot show the figure.
plt.show()
```

plt.figure(figsize = (12, 2)) for phase in phases: plt.plot(t[tidx], phase[tidx]) plt.xlim(tlim) plt.tight_layout() plt.show()

```
/home/rph / Projects / bycycle / tutorials / plot_1_bycycle_philosophy.py: 131: UserWarning: Matplotlib is currently using agg, which is a non - GUI backend, so cannot show the figure.
plt.show()
```

Macbook pro (M1, 2020)

```
import matplotlib.pyplot as plt
from scipy
import signal as sp
from time
import time
import medfilt as mf
import pandas as pd
import numpy as np
```

print(sp.signal.medfilt(all_result))

```
Traceback (most recent call last):
File "/Users/bahk_insung/Documents/Github/ecg-dbn/data/median_filter.py", line 37, in <module>
print(sp.signal.medfilt(all_result))
AttributeError: module 'scipy.signal' has no attribute 'signal'
```