Fix My Tutorial
Report

Understanding the FFT Algorithm

Open the original tutorial
Fixed Python 3.12 · checked 17 Oct 2026 · model cost $0.022

The tutorial's FFT implementation failed under Python 3 because the '/' operator produced floats used as slice indices, raising a TypeError. Replacing '/' with '//' for integer division resolved the error, allowing the code to run correctly.

2 changes to make it work today

Define recursive FFT

s5 · run_code migrate

Change N/2 to N//2 so slice indices are integers in Python 3.

@@ -12,4 +12,4 @@
X_odd = FFT(x[1::2])
factor = np.exp(-2j * np.pi * np.arange(N) / N)
- return np.concatenate([X_even + factor[:N / 2] * X_odd,
- X_even + factor[N / 2:] * X_odd])
+ return np.concatenate([X_even + factor[:N // 2] * X_odd,
+ X_even + factor[N // 2:] * X_odd])

Sources

  • TypeError: slice indices must be integers or None or have an __index__ method - LEfSe - The bioBakery help forumdverma2@EB-ONC-J8Q3FF3:/mnt/f/coin/LEfSe/pathway$ lefse\_plot\_res.py res\_pathway.res Pathway\_small.png Traceback (most recent call last): File “/home/dverma2/miniforge3/bin/lefse\_plot\_res.py”, line 10, in sys.exit(plot\_res()) File “/home/dverma2/miniforge3/lib/python3.10/site-packages/lefse/lefse\_plot\_res.py”, line 177, in plot\_res else: plot\_histo\_hor(params[‘output\_file’],params,data,len(data[‘cls’]) == 2,params[‘report\_features’]) File “/home/dverma2/miniforge3/lib/python3.10/site-packages/lefse/lefse\_plot\_res.py”, line 104, in plot\_histo\_hor if len(rr) > params[‘max\_featu
  • Slice indices must be integers or None or have an __index | Career KarmaThe “TypeError: slice indices must be integers or None or have an \_\_index\_\_ method” error is raised when you try to slice a list using a value that is not an integer, such as a float. [...] # Python TypeError: slice indices must be integers or None or have an \_\_index\_\_ method Solution
  • Lefse_plot_res.py plot error - TypeError: slice indices must be integers or None or have an __index__ method - LEfSe - The bioBakery help forumFile "/miniconda/envs/myenv/lib/python3.7/site-packages/lefse/lefse_plot_res.py", line 104, in plot_histo_hor if len(rr) > params['max_feature_len']: rr = rr[:params['max_feature_len']/2-2]+" [..]"+rr[-params['max_feature_len']/2+2:] TypeError: slice indices must be integers or None or have an __index__ method` [...] UNMAPPED 5.698806339377007 MF 4.992992452183536 0.0020039311821839286 UNINTEGRATED 5.534112533646385 NM 4.691403253999157 0.0016752988184979575 UNINTEGRATED.g\_\_Achromobacter\_s\_\_Achromobacter\_denitrificans 1.8462237235380918 - UNINTEGRATED.g\_\_Achromobacter\_s\_\_Achromobact

Define vectorized FFT

s8 · run_code migrate

Change X.shape[1]/2 to X.shape[1]//2 so slice indices are integers in Python 3.

@@ -19,6 +19,6 @@
# build-up each level of the recursive calculation all at once
while X.shape[0] < N:
- X_even = X[:, :X.shape[1] / 2]
- X_odd = X[:, X.shape[1] / 2:]
+ X_even = X[:, :X.shape[1] // 2]
+ X_odd = X[:, X.shape[1] // 2:]
factor = np.exp(-1j * np.pi * np.arange(X.shape[0])
/ X.shape[0])[:, None]

Sources

  • TypeError: slice indices must be integers or None or have an __index__ method - LEfSe - The bioBakery help forumdverma2@EB-ONC-J8Q3FF3:/mnt/f/coin/LEfSe/pathway$ lefse\_plot\_res.py res\_pathway.res Pathway\_small.png Traceback (most recent call last): File “/home/dverma2/miniforge3/bin/lefse\_plot\_res.py”, line 10, in sys.exit(plot\_res()) File “/home/dverma2/miniforge3/lib/python3.10/site-packages/lefse/lefse\_plot\_res.py”, line 177, in plot\_res else: plot\_histo\_hor(params[‘output\_file’],params,data,len(data[‘cls’]) == 2,params[‘report\_features’]) File “/home/dverma2/miniforge3/lib/python3.10/site-packages/lefse/lefse\_plot\_res.py”, line 104, in plot\_histo\_hor if len(rr) > params[‘max\_featu
  • Slice indices must be integers or None or have an __index | Career KarmaThe “TypeError: slice indices must be integers or None or have an \_\_index\_\_ method” error is raised when you try to slice a list using a value that is not an integer, such as a float. [...] # Python TypeError: slice indices must be integers or None or have an \_\_index\_\_ method Solution
  • Lefse_plot_res.py plot error - TypeError: slice indices must be integers or None or have an __index__ method - LEfSe - The bioBakery help forumFile "/miniconda/envs/myenv/lib/python3.7/site-packages/lefse/lefse_plot_res.py", line 104, in plot_histo_hor if len(rr) > params['max_feature_len']: rr = rr[:params['max_feature_len']/2-2]+" [..]"+rr[-params['max_feature_len']/2+2:] TypeError: slice indices must be integers or None or have an __index__ method` [...] UNMAPPED 5.698806339377007 MF 4.992992452183536 0.0020039311821839286 UNINTEGRATED 5.534112533646385 NM 4.691403253999157 0.0016752988184979575 UNINTEGRATED.g\_\_Achromobacter\_s\_\_Achromobacter\_denitrificans 1.8462237235380918 - UNINTEGRATED.g\_\_Achromobacter\_s\_\_Achromobact

Tell the author

Send them what broke and the fix, so the next reader doesn't hit the same error.

Badge

Add it to the tutorial so readers know when it was last checked.

Fix My Tutorial badge
Markdown
[![Fix My Tutorial](https://fix-my-tutorial.onrender.com/badge/ri-wU-0hfz3.svg)](https://fix-my-tutorial.onrender.com/r/ri-wU-0hfz3)
HTML
<a href="https://fix-my-tutorial.onrender.com/r/ri-wU-0hfz3"><img src="https://fix-my-tutorial.onrender.com/badge/ri-wU-0hfz3.svg" alt="Fix My Tutorial"></a>