KeyError: 2 in qcut - python

I want to do bucketing on one of the column of my dataframe. I have 2 columns, Category & Rank.
I want to do bucketing in each category. So i first groupby on category & then use qcut on each group to do bucketing. After groupby, my dataframe's group looks like (final_data.groupby(['category'])['Ranks'].groups)
{'north': [1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 13, 14, 17, 18, 19, 21, 22, 23, 24, 25, 2, 3, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 23, 24, 25, 29, 30, 31, 32, 33, 34, 36, 37, 38, 39, 40, 41, 42, 43, 44], 'south': [0, 5, 12, 15, 16, 20, 26, 27, 0, 1, 9, 10, 21, 26, 27, 28, 35, 45, 46, 47]}
I'm applying this code to bucketing
final_data.groupby(['category'])['Rank'].transform(lambda g: pd.qcut(g, q=[0.0, .1, .25, .5, .75, .9, 1.0], labels= ["Top 10", "11-25", "26-50", "50-75", "75-90" ,"Bottom10"]))
The above code is throwing the error

Related

Python Append items to dictionary in a loop

I am trying to append values to a dictionary inside a loop, but somehow it's only appending one of the values. I recreated the setup using the same numbers I am dynamically getting.
The output from "print(vertex_id_from_shell)" is "{0: [4], 1: [12], 2: [20]}". I need to keep the keys, but add the remaining numbers to the values.
Thanks.
shells = {0: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], 1: [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27], 2: [28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41]}
uvsID = [0, 1, 3, 2, 2, 3, 5, 4, 4, 5, 7, 6, 6, 7, 9, 8, 1, 10, 11, 3, 12, 0, 2, 13, 14, 15, 16, 17, 17, 16, 18, 19, 19, 18, 20, 21, 21, 20, 22, 23, 15, 24, 25, 16, 26, 14, 17, 27, 28, 29, 30, 31, 31, 30, 32, 33, 33, 32, 34, 35, 35, 34, 36, 37, 29, 38, 39, 30, 40, 28, 31, 41]
vertsID = [0, 1, 3, 2, 2, 3, 5, 4, 4, 5, 7, 6, 6, 7, 1, 0, 1, 7, 5, 3, 6, 0, 2, 4, 8, 9, 11, 10, 10, 11, 13, 12, 12, 13, 15, 14, 14, 15, 9, 8, 9, 15, 13, 11, 14, 8, 10, 12, 16, 17, 19, 18, 18, 19, 21, 20, 20, 21, 23, 22, 22, 23, 17, 16, 17, 23, 21, 19, 22, 16, 18, 20]
vertex_id_from_shell = {}
for shell in shells:
selection_shell = shells.get(shell)
#print(selection_shell)
for idx, item in enumerate(selection_shell):
if item in uvsID:
uv_index = uvsID.index(item)
vertex_ids = vertsID[uv_index]
vertex_id_from_shell[shell] = [ ( vertex_ids ) ]
print(vertex_id_from_shell)
#{0: [4], 1: [12], 2: [20]}
#desired result
{0: [0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 7, 0, 1, 7, 5, 6, 4], 1: [8, 9, 11, 10, 13, 12, 15, 14, 9, 8, 15, 13, 14, 12], 2: [16, 17, 19, 18, 21, 20, 23, 22, 17, 16, 23, 21, 22, 20]}
You're overwriting vertex_id_from_shell[shell] each time through the loop, not appending to it.
Use collections.defaultdict() to automatically create the dictionary elements with an empty list if necessary, then you can append.
from collections import defaultdict
vertex_id_from_shell = defaultdict(list)
for shell, selection_shell in shells.items():
for item in selection_shell:
if item in uvsID:
uv_index = uvsID.index(item)
vertex_ids = vertsID[uv_index]
vertex_id_from_shell[shell].append(vertex_ids)
You are setting vertex_id_from_shell[shell] to a new list, containing only one item every time. Instead, you should append to it.But first, of course that list needs to exist, so you should check and create it if it doesn't already exist.
shells = {0: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], 1: [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27], 2: [28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41]}
uvsID = [0, 1, 3, 2, 2, 3, 5, 4, 4, 5, 7, 6, 6, 7, 9, 8, 1, 10, 11, 3, 12, 0, 2, 13, 14, 15, 16, 17, 17, 16, 18, 19, 19, 18, 20, 21, 21, 20, 22, 23, 15, 24, 25, 16, 26, 14, 17, 27, 28, 29, 30, 31, 31, 30, 32, 33, 33, 32, 34, 35, 35, 34, 36, 37, 29, 38, 39, 30, 40, 28, 31, 41]
vertsID = [0, 1, 3, 2, 2, 3, 5, 4, 4, 5, 7, 6, 6, 7, 1, 0, 1, 7, 5, 3, 6, 0, 2, 4, 8, 9, 11, 10, 10, 11, 13, 12, 12, 13, 15, 14, 14, 15, 9, 8, 9, 15, 13, 11, 14, 8, 10, 12, 16, 17, 19, 18, 18, 19, 21, 20, 20, 21, 23, 22, 22, 23, 17, 16, 17, 23, 21, 19, 22, 16, 18, 20]
vertex_id_from_shell = {}
for shell in shells:
selection_shell = shells.get(shell)
#print(selection_shell)
for idx, item in enumerate(selection_shell):
if item in uvsID:
uv_index = uvsID.index(item)
vertex_ids = vertsID[uv_index]
# if the list does not exist, create it
if shell not in vertex_id_from_shell:
vertex_id_from_shell[shell] = []
# append to list
vertex_id_from_shell[shell].append(vertex_ids)
print(vertex_id_from_shell)
# {0: [0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 7, 5, 6, 4],
# 1: [8, 9, 11, 10, 13, 12, 15, 14, 9, 8, 15, 13, 14, 12],
# 2: [16, 17, 19, 18, 21, 20, 23, 22, 17, 16, 23, 21, 22, 20]}

How to sort a dictionary by value if the value is a sorted list?

I am trying to sort a dictionary based on the value (which is a sorted list).
for example, I have these dictionary items:
1:[2, 6, 10, 14, 20, 46]
2:[1, 2, 3, 14, 16, 18, 23, 37, 41]
3:[1, 2, 4, 6, 10, 27, 45, 290]
4:[3, 5, 13, 34, 39, 40, 47, 555]
I want the output to be like this:
2:[1, 2, 3, 14, 16, 18, 23, 37, 41]
3:[1, 2, 4, 6, 10, 27, 45, 290]
1:[2, 6, 10, 14, 20, 46]
4:[3, 5, 13, 34, 39, 40, 47, 555]
Something like this should do the trick.
x = {
1:[2, 6, 10, 14, 20, 46],
2:[1, 2, 3, 14, 16, 18, 23, 37, 41],
3:[1, 2, 4, 6, 10, 27, 45, 290],
4:[3, 5, 13, 34, 39, 40, 47, 555]
}
b = sorted(x.items(), key=lambda i: i[1])
print(b)
Output:
[(2, [1, 2, 3, 14, 16, 18, 23, 37, 41]), (3, [1, 2, 4, 6, 10, 27, 45, 290]), (1, [2, 6, 10, 14, 20, 46]), (4, [3, 5, 13, 34, 39, 40, 47, 555])]

how to add box plot to scatter data in matplotlib

I have the following data and after plotting scatter data point, I would like to add boxplot around each set of position. Here is my code for plotting the scatter plot:
%matplotlib inline
import matplotlib.pyplot as plt
X = [1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6,
7, 7, 7, 7, 7, 7, 7,
8, 8, 8, 8, 8, 8, 8,
9, 9, 9, 9, 9, 9, 9,
10, 10, 10, 10, 10, 10, 10,
11, 11, 11, 11, 11, 11, 11,
12, 12, 12, 12, 12, 12, 12,
13, 13, 13, 13, 13, 13, 13,
14, 14, 14, 14, 14, 14, 14,
15, 15, 15, 15, 15, 15, 15]
H = [15, 17, 16, 20, 15, 18, 15,
17, 16, 16, 20, 19, 18, 15,
20, 22, 20, 22, 19, 21, 21,
19, 21, 20, 23, 21, 20, 22,
21, 23, 22, 20, 24, 22, 20,
20, 19, 20, 18, 21, 17, 19,
18, 20, 16, 15, 17, 20, 19,
19, 19, 18, 21, 21, 16, 19,
21, 22, 22, 24, 24, 23, 25,
28, 26, 30, 27, 26, 29, 30,
27, 26, 29, 31, 27, 29, 30,
25, 26, 27, 28, 25, 27, 30,
31, 28, 25, 27, 30, 25, 31,
28, 26, 30, 28, 29, 27, 31,
24, 26, 25, 28, 26, 23, 25]
fig, axes = plt.subplots(figsize=(8,5))
axes.scatter(X, H, color='b')
axes.set_xlabel('Pos');
axes.set_ylabel('H, µm');
when i add plt.boxplot, it captures all data not individual position. I appreciate the answers either in matplotlib or seaborn.
thanks
A good way would be using pandas:
df = pd.DataFrame({'X':X, 'H': H})
ax=df.plot(kind='scatter', x='X', y='H')
df.boxplot(by='X', ax=ax)
plt.show()
output:
Here's a condensed solution to how to map your H array by X and plot it using matplotlib:
groups = [[] for i in range(max(X))]
[groups[X[i]-1].append(H[i]) for i in range(len(H))]
plt.boxplot(groups)
Outcome:
you can add grid with plt.grid(True)

Trouble printing strings and percentages

Here's my Code:
from collections import Counter
Value = (3, 19, 23, 27, 36, 10, 25, 29, 39, 41, 9, 16, 20, 31, 34, 2, 8, 9, 33, 37, 4, 21, 27, 28, 35, 2, 12, 21, 23, 38, 4, 5, 12, 16, 20, 1, 8, 21, 33, 38, 1, 9, 12, 18, 36, 5, 17, 20, 22, 25, 14, 21, 27, 31, 41, 11, 12, 23, 28, 41, 9, 22, 25, 34, 35, 5, 12, 19, 22, 39, 5, 13, 14, 17, 33, 4, 16, 26, 27, 37, 9, 18, 31, 34, 39, 9, 17, 33, 35, 40, 16, 20, 22, 37, 40, 2, 14, 19, 22, 32, 4, 5, 21, 29, 36, 2, 9, 22, 32, 35, 9, 13, 24, 36, 40, 3, 7, 9, 10, 28, 4, 20, 21, 23, 41, 12, 18, 26, 28, 34, 3, 23, 24, 27, 37, 4, 5, 26, 34, 36, 3, 5, 15, 25, 34, 4, 7, 9, 23, 32, 5, 7, 19, 29, 34, 2, 4, 25, 34, 38, 1, 4, 24, 32, 33, 20, 23, 31, 37, 40, 1, 20, 31, 36, 37, 1, 18, 30, 32, 41, 4, 8, 24, 26, 33, 3, 12, 13, 27, 34, 3, 6, 16, 24, 28, 10, 17, 20, 30, 32, 8, 10, 27, 28, 29, 6, 21, 23, 30, 32, 1, 22, 29, 33, 36, 1, 6, 9, 28, 30, 9, 12, 14, 19, 31, 1, 2, 10, 29, 37, 2, 7, 19, 20, 27, 7, 9, 30, 35, 37, 14, 23, 25, 29, 30, 4, 11, 19, 27, 32, 11, 15, 23, 26, 35, 14, 18, 22, 26, 28, 4, 17, 18, 23, 40, 10, 11, 16, 37, 39, 2, 12, 15, 27, 29, 3, 11, 20, 21, 26, 11, 17, 29, 31, 38, 9, 14, 15, 31, 32, 14, 25, 29, 35, 40, 1, 5, 8, 17, 27, 6, 14, 16, 18, 20, 13, 15, 29, 33, 35, 10, 18, 26, 38, 41, 13, 16, 20, 26, 27, 4, 12, 27, 32, 33, 7, 10, 26, 30, 31, 5, 7, 17, 37, 38, 3, 6, 10, 27, 38, 5, 15, 23, 33, 36, 11, 15, 31, 34, 38, 8, 9, 11, 15, 25, 6, 7, 21, 30, 33, 4, 17, 21, 34, 35, 3, 8, 16, 22, 34, 5, 23, 28, 31, 39, 7, 18, 24, 33, 40, 5, 24, 30, 38, 41, 3, 11, 25, 27, 37, 19, 26, 34, 36, 40, 20, 27, 30, 32, 38, 1, 16, 17, 26, 30, 6, 11, 14, 17, 28, 11, 18, 27, 33, 38, 4, 6, 7, 8, 25, 7, 28, 30, 35, 39, 20, 27, 31, 38, 41, 18, 27, 35, 37, 38, 17, 30, 32, 38, 39, 11, 12, 24, 33, 36, 1, 3, 8, 25, 34, 2, 3, 7, 15, 35, 8, 18, 19, 27, 32, 1, 3, 11, 15, 26, 15, 17, 21, 29, 36, 4, 16, 22, 24, 25, 3, 4, 19, 31, 35, 1, 15, 26, 33, 35, 8, 15, 29, 39, 40, 14, 19, 27, 32, 34, 8, 12, 22, 23, 28, 13, 28, 29, 31, 40, 1, 4, 16, 18, 26, 5, 8, 25, 31, 39, 5, 8, 16, 32, 33, 6, 11, 15, 21, 37, 19, 27, 32, 36, 37, 3, 10, 16, 25, 34, 5, 12, 18, 23, 37, 1, 11, 20, 30, 37, 11, 16, 29, 31, 39, 4, 13, 23, 28, 39, 9, 15, 25, 28, 32, 1, 7, 18, 20, 25, 8, 9, 25, 28, 33, 4, 10, 22, 26, 33, 4, 8, 9, 11, 27, 13, 21, 26, 30, 41, 1, 15, 24, 33, 39, 8, 11, 27, 34, 41, 12, 13, 14, 25, 34, 14, 16, 21, 31, 39, 4, 17, 18, 27, 37, 5, 10, 11, 15, 32, 6, 14, 27, 35, 36, 4, 14, 28, 34, 38, 1, 11, 14, 22, 30, 4, 5, 8, 23, 33, 3, 6, 14, 19, 32, 2, 19, 20, 23, 34, 3, 4, 14, 18, 29, 7, 10, 26, 37, 41, 12, 15, 19, 26, 34, 9, 15, 26, 27, 36, 2, 5, 22, 27, 34, 2, 13, 14, 21, 26, 8, 22, 23, 29, 37, 2, 18, 23, 24, 36, 3, 13, 19, 26, 37, 15, 17, 18, 24, 41, 5, 8, 12, 13, 34, 4, 9, 13, 28, 39, 6, 13, 21, 28, 29, 1, 7, 17, 29, 38, 11, 18, 25, 31, 39, 1, 2, 18, 26, 33, 10, 14, 16, 17, 34, 13, 15, 28, 29, 30, 2, 10, 12, 13, 41, 11, 13, 26, 27, 32, 3, 4, 30, 33, 40, 1, 7, 15, 19, 26, 4, 5, 14, 18, 34, 3, 5, 6, 33, 40, 10, 20, 23, 25, 39, 11, 13, 21, 36, 41, 18, 22, 30, 33, 36, 1, 7, 10, 12, 17, 9, 15, 23, 32, 38, 6, 8, 32, 33, 40, 14, 21, 31, 32, 36, 11, 23, 24, 33, 34, 8, 13, 17, 20, 36, 10, 16, 27, 30, 33, 1, 3, 4, 6, 23, 2, 4, 22, 32, 38, 2, 15, 18, 19, 21, 2, 4, 5, 20, 21, 21, 22, 29, 38, 40, 10, 27, 28, 32, 37, 5, 6, 8, 37, 40, 2, 9, 11, 40, 41, 10, 11, 17, 28, 34, 13, 15, 17, 18, 37, 9, 14, 21, 34, 35, 20, 22, 26, 33, 37, 3, 16, 18, 28, 31, 3, 24, 31, 33, 37, 1, 27, 28, 38, 40, 4, 20, 25, 33, 40, 7, 23, 25, 27, 32, 5, 6, 7, 13, 28, 3, 7, 17, 30, 36, 9, 18, 20, 37, 40, 1, 14, 21, 27, 37, 7, 18, 22, 23, 34, 10, 12, 25, 26, 40, 4, 9, 32, 34, 38, 2, 13, 16, 24, 33, 4, 18, 25, 30, 40, 7, 10, 27, 28, 33, 13, 16, 21, 27, 29, 10, 21, 32, 34, 35, 6, 16, 17, 22, 27, 16, 21, 24, 40, 41, 1, 2, 5, 9, 37, 1, 10, 17, 19, 37, 11, 20, 21, 30, 36, 1, 5, 22, 26, 30, 9, 12, 25, 34, 38, 2, 3, 6, 18, 28, 3, 6, 20, 22, 26, 3, 4, 9, 24, 27, 4, 7, 29, 32, 36, 4, 11, 18, 37, 40, 13, 15, 23, 34, 41, 17, 18, 34, 35, 36, 2, 14, 26, 33, 38, 1, 4, 22, 23, 32, 6, 13, 19, 33, 39, 8, 11, 12, 29, 40, 1, 4, 9, 11, 16, 5, 6, 13, 15, 28, 3, 10, 18, 19, 40, 1, 15, 25, 28, 38, 4, 19, 23, 26, 28, 1, 5, 11, 12, 36, 3, 14, 19, 23, 38, 1, 5, 9, 11, 35, 6, 10, 19, 23, 30, 14, 16, 23, 35, 40, 3, 5, 10, 15, 35, 4, 28, 33, 38, 41, 2, 17, 20, 22, 30, 7, 19, 20, 26, 31, 11, 13, 16, 17, 25, 3, 10, 16, 28, 39, 9, 18, 29, 37, 40, 2, 3, 25, 34, 41, 11, 28, 33, 38, 40, 4, 5, 9, 23, 41, 2, 9, 10, 22, 41, 1, 4, 9, 20, 27, 4, 7, 17, 24, 27, 3, 14, 15, 24, 29, 9, 13, 15, 27, 37, 17, 19, 26, 30, 34, 12, 16, 19, 21, 41, 1, 16, 24, 29, 39, 8, 21, 23, 25, 32, 2, 3, 22, 24, 40, 13, 15, 17, 28, 33, 1, 6, 19, 38, 41, 7, 17, 18, 21, 26, 3, 8, 21, 30, 35, 2, 24, 29, 33, 38, 7, 17, 18, 31, 36, 24, 31, 33, 38, 39, 21, 24, 27, 35, 41, 5, 9, 17, 23, 40, 17, 22, 29, 32, 34, 13, 14, 25, 36, 39, 2, 10, 22, 30, 32, 2, 16, 23, 28, 38, 5, 27, 30, 36, 41, 8, 23, 26, 29, 38, 6, 11, 22, 37, 38, 9, 26, 30, 35, 36, 10, 19, 29, 32, 40, 6, 11, 26, 27, 40, 1, 16, 21, 30, 33, 13, 21, 22, 33, 34, 5, 13, 23, 26, 37, 2, 11, 21, 24, 37, 4, 5, 20, 31, 34, 1, 20, 22, 27, 33, 1, 6, 11, 12, 14, 5, 10, 11, 36, 40, 5, 15, 36, 38, 39, 3, 6, 9, 17, 28, 13, 21, 24, 26, 37, 6, 10, 14, 17, 37, 5, 18, 23, 36, 38, 11, 13, 28, 36, 38, 5, 8, 17, 29, 41, 2, 12, 14, 27, 39, 4, 11, 20, 21, 39, 2, 6, 14, 31, 38, 2, 25, 26, 32, 33, 4, 10, 26, 32, 37, 5, 13, 14, 32, 41, 1, 4, 20, 21, 27, 2, 7, 14, 32, 34, 9, 12, 23, 24, 29, 9, 19, 22, 30, 33, 7, 13, 19, 35, 41, 1, 18, 19, 21, 24, 15, 18, 29, 31, 33, 14, 15, 16, 29, 35, 5, 16, 21, 33, 36, 12, 17, 23, 32, 34, 17, 20, 23, 33, 40, 5, 9, 24, 30, 34, 9, 14, 21, 26, 28, 1, 7, 19, 21, 24, 1, 5, 22, 33, 37, 1, 5, 17, 23, 29, 3, 11, 17, 24, 30, 7, 12, 18, 22, 34, 5, 7, 13, 21, 38, 9, 24, 32, 40, 41, 3, 17, 26, 33, 38, 5, 6, 7, 14, 30, 8, 19, 20, 28, 30, 4, 15, 26, 29, 32, 5, 7, 25, 28, 35, 10, 23, 35, 37, 41, 3, 11, 17, 19, 41, 4, 24, 25, 29, 34, 8, 22, 25, 27, 33, 2, 16, 20, 30, 31, 14, 19, 20, 33, 35, 15, 16, 17, 20, 38, 14, 23, 28, 29, 34, 7, 21, 26, 29, 36, 8, 9, 10, 25, 30, 12, 17, 26, 28, 36, 6, 10, 11, 20, 40, 7, 8, 21, 40, 41, 9, 15, 23, 33, 36, 1, 9, 27, 35, 36, 9, 13, 17, 18, 41, 12, 13, 24, 25, 29, 16, 21, 23, 36, 39, 6, 9, 19, 26, 28, 11, 27, 30, 35, 37, 3, 6, 23, 34, 38, 9, 14, 19, 24, 35, 5, 6, 20, 33, 41, 9, 13, 33, 37, 38, 9, 13, 24, 25, 36, 11, 15, 20, 36, 38, 6, 19, 24, 25, 37, 8, 12, 27, 33, 34, 9, 12, 18, 28, 36, 12, 17, 29, 34, 40, 1, 2, 10, 24, 34, 7, 25, 31, 36, 39, 1, 6, 7, 21, 28, 4, 5, 6, 18, 39, 22, 24, 26, 29, 36, 12, 23, 30, 31, 39, 28, 34, 35, 37, 38, 4, 8, 11, 22, 25, 5, 10, 23, 33, 40, 9, 19, 21, 34, 38, 6, 8, 9, 19, 35, 16, 32, 33, 34, 37, 1, 3, 6, 12, 15, 4, 29, 30, 39, 40, 16, 21, 24, 32, 36, 8, 19, 25, 30, 34, 10, 18, 24, 25, 39, 20, 24, 27, 28, 38, 12, 16, 18, 20, 31, 1, 11, 13, 19, 36, 20, 22, 25, 34, 38, 2, 10, 17, 27, 35, 4, 6, 8, 26, 40, 9, 12, 21, 28, 30, 19, 21, 26, 28, 37, 2, 4, 5, 32, 36, 15, 22, 25, 31, 41, 7, 13, 16, 29, 39, 10, 21, 23, 25, 37, 18, 22, 30, 35, 38, 10, 12, 13, 18, 39, 14, 17, 20, 30, 36, 21, 24, 25, 29, 35, 4, 7, 22, 33, 36, 3, 7, 10, 23, 37, 8, 9, 14, 25, 31, 7, 11, 30, 38, 40, 12, 13, 18, 26, 40, 2, 12, 22, 26, 36, 2, 19, 20, 23, 24, 1, 5, 16, 17, 27, 8, 17, 22, 35, 38, 1, 3, 19, 36, 38, 1, 12, 29, 35, 38, 2, 3, 27, 39, 41, 7, 11, 26, 35, 36, 14, 16, 18, 31, 35, 17, 24, 35, 38, 41, 3, 11, 27, 31, 37, 3, 25, 26, 29, 32, 8, 17, 19, 30, 33, 3, 18, 28, 31, 32, 1, 9, 13, 25, 36, 4, 6, 8, 17, 29, 7, 11, 24, 32, 33, 2, 7, 20, 26, 41, 5, 7, 14, 28, 38, 3, 8, 9, 21, 26, 5, 11, 25, 40, 41, 10, 13, 14, 29, 34, 3, 5, 15, 31, 37, 16, 24, 27, 31, 34, 4, 13, 16, 27, 40, 24, 26, 27, 32, 39, 10, 11, 12, 15, 23, 15, 31, 34, 36, 38, 5, 9, 21, 29, 35, 9, 13, 17, 22, 40, 13, 22, 28, 36, 39, 5, 16, 17, 19, 30, 13, 18, 25, 26, 38, 1, 5, 9, 27, 28, 3, 5, 19, 37, 39, 10, 13, 24, 32, 40, 3, 7, 8, 17, 24, 1, 10, 11, 12, 20, 4, 11, 15, 19, 23, 17, 26, 30, 38, 39, 6, 7, 10, 31, 41, 18, 21, 24, 32, 39, 4, 8, 12, 17, 24, 3, 4, 7, 23, 38, 11, 17, 23, 29, 34, 1, 10, 25, 30, 32, 2, 18, 20, 24, 27, 16, 24, 27, 31, 38, 1, 13, 17, 18, 36, 6, 8, 13, 20, 24, 5, 13, 16, 25, 29, 7, 13, 32, 33, 34, 15, 19, 26, 31, 35, 5, 9, 14, 21, 26, 1, 10, 16, 20, 31, 1, 6, 25, 33, 35, 3, 13, 14, 17, 30, 2, 5, 9, 38, 39, 22, 24, 27, 35, 36, 10, 18, 20, 27, 36, 5, 7, 20, 33, 35, 3, 8, 13, 21, 37, 13, 19, 22, 25, 39, 3, 14, 21, 23, 38, 15, 20, 30, 32, 35, 8, 9, 12, 24, 32, 10, 25, 35, 36, 37, 1, 11, 14, 18, 36, 7, 9, 25, 31, 38, 4, 5, 6, 16, 34, 5, 8, 9, 14, 28, 12, 17, 20, 23, 33, 1, 4, 8, 20, 25, 1, 8, 15, 27, 34, 10, 14, 15, 18, 23, 3, 18, 29, 31, 33, 6, 10, 16, 18, 21, 1, 4, 11, 14, 25, 7, 11, 19, 28, 37, 8, 13, 22, 28, 33, 10, 11, 14, 20, 37, 13, 15, 17, 19, 36, 10, 22, 26, 33, 36, 10, 15, 18, 19, 35, 8, 9, 20, 31, 33, 3, 8, 18, 31, 34, 2, 14, 24, 27, 31, 9, 11, 12, 15, 22, 13, 14, 15, 37, 39, 3, 4, 7, 27, 34, 6, 14, 24, 30, 38, 2, 3, 19, 21, 30, 5, 6, 15, 31, 32, 1, 6, 24, 26, 30, 9, 11, 25, 29, 30, 1, 16, 22, 30, 34, 1, 2, 12, 19, 34, 4, 10, 13, 20, 31, 18, 28, 33, 35, 39, 22, 23, 25, 27, 36, 1, 7, 28, 33, 34, 1, 12, 14, 32, 39, 16, 25, 28, 30, 32, 12, 19, 28, 31, 39, 12, 19, 25, 27, 32, 8, 14, 20, 31, 38, 10, 19, 21, 23, 32, 2, 3, 24, 30, 36, 3, 11, 22, 26, 39, 4, 13, 29, 33, 37, 9, 22, 30, 36, 39, 2, 8, 9, 33, 34, 2, 5, 15, 23, 28, 11, 23, 26, 29, 31, 10, 13, 15, 29, 34, 13, 18, 21, 22, 32, 4, 5, 7, 20, 24, 1, 15, 17, 29, 38, 2, 7, 20, 35, 38, 26, 33, 36, 37, 38, 3, 5, 14, 24, 39, 7, 8, 9, 24, 28, 8, 18, 29, 36, 37, 7, 10, 21, 25, 29, 3, 8, 26, 35, 36, 1, 21, 22, 24, 36, 5, 7, 19, 33, 37, 8, 22, 29, 30, 37, 5, 7, 14, 17, 25, 11, 22, 26, 33, 38, 7, 19, 20, 27, 34, 11, 18, 19, 30, 37, 5, 11, 14, 34, 38, 6, 9, 23, 29, 39, 2, 16, 22, 24, 37, 1, 8, 9, 29, 35, 15, 18, 20, 23, 28, 10, 14, 26, 30, 37, 3, 4, 6, 30, 36, 2, 5, 8, 18, 27, 5, 9, 21, 35, 37, 6, 8, 14, 22, 38, 21, 22, 27, 29, 37, 3, 4, 11, 34, 38, 7, 12, 17, 21, 32, 4, 8, 15, 26, 38, 6, 8, 23, 33, 35, 7, 19, 27, 37, 39, 4, 10, 24, 25, 38, 3, 5, 21, 36, 37, 6, 20, 27, 30, 34, 10, 14, 19, 21, 29, 13, 15, 30, 36, 37, 2, 15, 17, 31, 32, 8, 17, 34, 36, 37, 1, 11, 26, 29, 35, 10, 16, 17, 35, 36, 3, 17, 22, 29, 32, 7, 9, 10, 18, 38, 1, 5, 15, 18, 24, 9, 11, 12, 14, 35, 7, 10, 28, 29, 34, 10, 21, 24, 26, 38, 7, 22, 26, 34, 39, 1, 8, 10, 25, 31, 2, 3, 9, 18, 28, 5, 10, 24, 32, 33, 2, 8, 13, 14, 37, 3, 11, 15, 33, 35, 11, 17, 23, 24, 28, 10, 14, 20, 35, 37, 1, 19, 24, 26, 38, 20, 30, 32, 36, 39, 6, 24, 28, 35, 38, 3, 9, 10, 19, 28, 18, 22, 25, 31, 33, 3, 6, 8, 20, 21, 7, 16, 19, 21, 39, 10, 19, 27, 31, 36, 13, 21, 26, 29, 37, 14, 15, 21, 24, 25, 5, 10, 17, 21, 29, 3, 12, 25, 26, 32, 12, 14, 21, 34, 36, 5, 9, 14, 15, 38, 2, 27, 28, 30, 39, 5, 9, 11, 18, 38, 7, 15, 27, 30, 38, 13, 20, 24, 27, 35, 14, 15, 19, 20, 22, 4, 10, 13, 16, 19, 1, 2, 16, 35, 38, 6, 10, 20, 27, 34, 5, 6, 11, 21, 34, 6, 15, 28, 30, 36, 2, 5, 26, 28, 33, 14, 19, 21, 23, 33, 9, 10, 20, 22, 30, 1, 2, 13, 29, 34, 1, 6, 13, 17, 18, 3, 8, 11, 21, 28, 4, 7, 10, 16, 22, 3, 5, 6, 15, 22, 22, 24, 32, 35, 38, 14, 18, 26, 27, 28, 14, 20, 24, 26, 35, 4, 24, 26, 33, 37, 2, 14, 16, 25, 29, 1, 3, 24, 26, 36, 8, 20, 30, 31, 36, 6, 9, 17, 24, 35, 14, 18, 27, 35, 39, 5, 15, 19, 37, 38, 4, 6, 11, 18, 26, 18, 21, 22, 26, 32, 3, 7, 19, 20, 21, 3, 5, 16, 21, 33, 6, 14, 20, 22, 35, 6, 11, 13, 25, 28, 8, 13, 16, 38, 39, 19, 20, 24, 27, 29, 5, 14, 22, 31, 38, 18, 20, 22, 32, 36, 16, 19, 25, 34, 39, 4, 16, 19, 33, 38, 19, 22, 29, 33, 39, 11, 22, 26, 30, 32, 5, 6, 25, 27, 36, 5, 20, 32, 37, 38, 6, 13, 31, 35, 39, 2, 6, 22, 37, 39, 8, 22, 27, 34, 35, 3, 10, 21, 24, 29, 7, 21, 24, 30, 35, 14, 16, 21, 36, 38, 5, 10, 25, 30, 33, 3, 5, 9, 17, 23, 2, 8, 26, 34, 38, 1, 7, 23, 31, 38, 1, 10, 16, 22, 38, 5, 8, 9, 18, 27, 7, 13, 22, 25, 34, 4, 6, 11, 30, 33, 16, 19, 20, 21, 39, 11, 19, 21, 31, 36, 2, 3, 6, 12, 24, 3, 12, 16, 20, 37, 11, 18, 27, 33, 39, 7, 21, 24, 27, 30, 15, 16, 18, 21, 31, 5, 10, 22, 25, 26, 11, 16, 18, 29, 35, 1, 9, 25, 31, 32, 6, 7, 10, 23, 31, 5, 22, 28, 29, 37, 15, 18, 19, 24, 39, 4, 9, 12, 25, 32, 5, 7, 30, 31, 37, 2, 4, 9, 31, 39, 8, 10, 15, 31, 39, 2, 9, 22, 24, 30, 6, 11, 21, 28, 29, 14, 19, 20, 32, 33, 12, 13, 15, 20, 33, 1, 2, 19, 22, 37, 2, 12, 30, 36, 39, 2, 3, 5, 7, 28, 2, 25, 28, 32, 33, 8, 16, 19, 25, 28, 19, 30, 31, 36, 39, 4, 12, 23, 26, 36, 10, 11, 21, 27, 29, 1, 2, 5, 8, 26, 1, 12, 16, 18, 25, 15, 20, 21, 24, 34, 7, 12, 19, 31, 32, 12, 17, 19, 26, 32, 9, 18, 23, 29, 36, 12, 16, 30, 37, 38, 1, 11, 18, 28, 31, 17, 23, 28, 31, 35, 7, 18, 23, 32, 33, 4, 13, 15, 35, 37, 3, 22, 24, 30, 34, 7, 9, 28, 30, 37, 5, 12, 24, 34, 39, 2, 4, 9, 10, 11, 1, 8, 15, 18, 20, 12, 15, 22, 23, 34, 6, 8, 14, 32, 33, 1, 7, 15, 22, 24, 9, 15, 16, 18, 38, 13, 17, 22, 28, 31, 12, 19, 22, 34, 35, 2, 7, 10, 15, 34, 13, 22, 25, 31, 37, 1, 16, 27, 30, 31, 12, 24, 28, 30, 32, 14, 17, 21, 30, 38, 2, 6, 12, 17, 27, 1, 2, 8, 18, 39, 6, 10, 12, 21, 28, 10, 20, 22, 29, 31, 1, 5, 12, 22, 23, 5, 7, 8, 21, 26, 4, 9, 14, 21, 24, 6, 31, 32, 34, 39, 7, 17, 24, 33, 34, 3, 16, 22, 24, 36, 1, 12, 20, 31, 35, 1, 2, 28, 34, 38, 5, 21, 27, 30, 36, 8, 10, 14, 31, 32, 1, 3, 16, 26, 35, 2, 4, 26, 30, 35, 2, 6, 24, 31, 36, 5, 11, 12, 15, 37, 2, 15, 16, 17, 20, 8, 10, 16, 38, 39, 2, 12, 14, 16, 39, 15, 17, 27, 31, 38, 1, 3, 16, 32, 35, 6, 14, 16, 23, 30, 12, 22, 31, 34, 37, 3, 10, 12, 22, 39, 4, 20, 28, 38, 39, 2, 7, 18, 35, 38, 6, 7, 10, 16, 31, 2, 7, 13, 34, 38, 17, 18, 24, 26, 29, 11, 17, 21, 26, 35, 2, 3, 12, 29, 31, 13, 15, 20, 25, 38, 15, 22, 30, 34, 39, 18, 22, 35, 37, 39, 3, 13, 14, 35, 37, 1, 5, 30, 31, 32, 6, 7, 12, 28, 34, 1, 3, 16, 23, 32, 1, 7, 8, 13, 22, 1, 4, 11, 20, 36, 6, 14, 27, 28, 29, 11, 14, 24, 25, 38, 1, 12, 26, 28, 29, 1, 6, 8, 22, 37, 5, 11, 22, 35, 37, 3, 7, 11, 15, 34, 4, 7, 22, 31, 33, 2, 7, 11, 19, 29, 18, 19, 21, 22, 25, 13, 17, 18, 19, 34, 1, 20, 24, 30, 38, 11, 13, 14, 35, 36, 3, 11, 28, 31, 34, 2, 6, 11, 27, 36, 1, 9, 11, 16, 25, 15, 16, 20, 26, 38, 4, 6, 31, 34, 36, 8, 14, 19, 23, 31, 11, 22, 23, 28, 39, 2, 16, 19, 36, 38, 8, 12, 33, 36, 37, 3, 11, 21, 30, 39, 3, 8, 9, 14, 29, 7, 9, 20, 21, 37, 8, 13, 14, 30, 35, 3, 11, 26, 37, 38, 2, 8, 15, 33, 34, 2, 9, 14, 17, 26, 2, 6, 15, 34, 35, 1, 7, 23, 24, 37, 5, 7, 10, 26, 30, 8, 10, 11, 22, 33, 5, 8, 20, 30, 33, 11, 15, 21, 28, 39, 15, 16, 17, 32, 33, 17, 23, 28, 29, 39, 4, 7, 14, 18, 39, 8, 17, 27, 35, 37, 5, 7, 18, 21, 37, 4, 17, 18, 25, 31, 20, 26, 28, 31, 35, 5, 11, 14, 19, 23, 4, 7, 17, 27, 30, 6, 26, 27, 33, 35, 22, 25, 35, 36, 38, 4, 13, 15, 23, 26, 7, 9, 28, 32, 39, 14, 22, 25, 35, 37, 10, 23, 25, 35, 38, 5, 16, 17, 20, 21, 6, 10, 27, 28, 35, 2, 9, 20, 31, 37, 1, 19, 26, 31, 36, 3, 12, 24, 27, 29, 10, 17, 18, 31, 37, 3, 13, 17, 26, 32, 2, 7, 19, 25, 31, 2, 8, 19, 23, 27, 9, 16, 28, 34, 35, 1, 12, 33, 35, 39, 11, 15, 24, 32, 36, 4, 8, 12, 13, 35, 8, 14, 18, 22, 28, 1, 20, 22, 31, 32, 2, 8, 16, 17, 35, 1, 10, 16, 20, 25, 6, 18, 23, 33, 38, 5, 10, 21, 22, 30, 13, 17, 18, 19, 35, 4, 10, 12, 20, 37, 20, 22, 24, 26, 32, 18, 26, 28, 30, 36, 1, 2, 21, 25, 33, 3, 4, 9, 16, 35, 5, 12, 14, 28, 29, 2, 10, 17, 21, 38, 1, 9, 11, 28, 34, 2, 33, 35, 37, 38, 2, 6, 10, 35, 38, 4, 13, 16, 19, 35, 4, 7, 9, 12, 15, 4, 7, 21, 30, 32, 6, 13, 22, 30, 32, 2, 9, 13, 18, 33, 3, 10, 29, 37, 38, 1, 13, 23, 27, 32, 14, 15, 17, 24, 27, 8, 10, 14, 26, 31, 5, 15, 17, 31, 35, 12, 27, 31, 33, 36, 9, 12, 13, 15, 38, 13, 16, 27, 29, 32, 8, 14, 20, 24, 26, 12, 19, 23, 24, 33, 2, 9, 14, 16, 19, 9, 24, 31, 38, 39, 13, 22, 25, 26, 35, 10, 14, 17, 24, 36, 8, 11, 16, 17, 32, 1, 11, 27, 28, 31, 15, 23, 34, 35, 36, 1, 7, 14, 17, 35, 1, 24, 36, 37, 39, 9, 13, 16, 23, 36, 12, 13, 23, 24, 37, 1, 7, 13, 31, 33, 8, 12, 16, 27, 28, 6, 13, 28, 29, 30, 9, 10, 22, 23, 39, 1, 3, 5, 27, 35, 6, 13, 16, 34, 39, 14, 23, 25, 34, 37, 9, 17, 18, 36, 37, 11, 16, 24, 30, 36, 9, 19, 22, 26, 34, 11, 20, 22, 26, 29, 5, 24, 28, 29, 32, 10, 23, 25, 30, 33, 6, 8, 22, 31, 33, 1, 8, 10, 23, 38, 5, 9, 12, 32, 33, 5, 29, 31, 33, 35, 1, 4, 19, 23, 37, 24, 29, 30, 32, 36, 5, 12, 13, 23, 33, 1, 17, 18, 25, 26, 6, 9, 20, 33, 39, 3, 25, 30, 34, 39, 1, 5, 11, 14, 26, 4, 12, 13, 31, 35, 19, 20, 23, 24, 36, 1, 2, 6, 24, 34, 15, 32, 35, 36, 37, 1, 8, 14, 25, 38, 5, 8, 21, 23, 34, 1, 4, 10, 34, 39, 6, 7, 24, 36, 37, 6, 8, 22, 26, 38, 11, 17, 24, 27, 35, 12, 13, 16, 21, 29, 17, 18, 19, 28, 38, 23, 25, 31, 32, 39, 22, 24, 30, 31, 37, 3, 17, 21, 27, 31, 4, 24, 27, 28, 33, 13, 16, 26, 27, 31, 6, 22, 24, 34, 39, 20, 27, 30, 35, 37, 1, 4, 7, 15, 26, 8, 14, 16, 32, 34, 5, 23, 27, 37, 38, 4, 7, 20, 29, 35, 2, 11, 18, 25, 36, 2, 4, 5, 6, 10, 8, 11, 21, 25, 31, 5, 12, 23, 24, 27, 16, 18, 19, 28, 39, 1, 11, 13, 18, 39, 4, 10, 12, 28, 30, 9, 13, 25, 26, 30, 9, 11, 16, 20, 38, 4, 7, 18, 33, 39, 4, 11, 17, 31, 37, 15, 31, 34, 36, 38, 9, 11, 29, 34, 37, 4, 12, 21, 23, 31, 11, 12, 13, 31, 38, 12, 18, 31, 33, 39, 5, 9, 14, 16, 30, 7, 9, 11, 17, 30, 2, 5, 7, 14, 22, 22, 24, 28, 29, 31, 1, 10, 20, 21, 32, 12, 29, 31, 32, 33, 8, 13, 20, 30, 33, 5, 6, 13, 23, 28, 6, 7, 18, 22, 25, 14, 18, 19, 22, 35, 4, 9, 11, 26, 31, 1, 21, 23, 24, 36, 12, 25, 26, 29, 34, 3, 11, 13, 20, 26, 12, 14, 23, 26, 33, 13, 22, 24, 29, 37, 1, 16, 17, 22, 29, 2, 12, 17, 32, 34, 2, 10, 21, 25, 29, 8, 25, 26, 34, 39, 2, 28, 31, 33, 34, 7, 11, 17, 18, 21, 3, 6, 8, 12, 37, 8, 10, 14, 17, 35, 20, 21, 25, 26, 38, 15, 19, 22, 23, 37, 9, 12, 15, 20, 25, 6, 9, 18, 23, 31, 19, 20, 27, 36, 38, 1, 5, 12, 28, 37, 1, 3, 6, 24, 25, 14, 23, 26, 32, 39, 8, 24, 29, 35, 36, 18, 21, 32, 36, 37)
V = Counter(Value)
print(V)
#For 'x' amount of number sets (from spreadsheet).
#List Size(Ex. 917) do 917x5
myInt = 4585
#Divide for percentage
percentdiv = [x / myInt for x in Value]
#Times new value by 100 and format 2 decimal places to get percentage
for i in percentdiv:
Percentage = ("%{:.2f}".format(i * 100))
for x in Value:
print (x, Percentage,)
I'm trying to figure out how to get python3 to print something like:
1 = %0.34, 2 = %0.21, 3 = %0.03
4 = %0.22, 5 = %0.13, 6 = %0.01
But for some reason I get:
1 %0.07
3 %0.07
8 %0.07
25 %0.07
34 %0.07
2 %0.07
3 %0.07
7 %0.07
15 %0.07
35 %0.07
8 %0.07
18 %0.07
19 %0.07
27 %0.07
32 %0.07
1 %0.07
I noticed too that the numbers were looping themselves.
I like what Counter does I like the formatting, but I need the percentage not just the number of times. Can someone help, please?
I think you need the percentage of each value's count in the Value list.Please correct if I am wrong,
for x,i in zip(Value,percentdiv):
print("{}={:.2f}".format(x,i*100),end='')
By default print function have the \n in a end so it should be,
import sys
for i in percentdiv:
Percentage = ("%{:.2f}".format(i * 100))
for x in Value:
sys.stdout.write(x, Percentage,)
sys.stdout.write("\n")
From here code copied

Re-order a numpy array python

I have a big two-dimensional array like this:
array([[ 1, 2, 3, 4, 5, 6, 7, 8],
[ 9,10,11,12,13,14,15,16],
[17,18,19,20,21,22,23,24],
[25,26,27,28,29,30,31,32],
[33,34,35,36,37,38,39,40],
[41,42,43,44,45,46,47,48],
....])
and I need to convert it into:
array([ 1, 9,17, 2,10,18, 3,11,19, 4,12,20, 5,13,21, 6,14,22, 7,15,23, 8,16,24],
[25,33,41,26,34,42,27,35,43,28,36,44,29,37,45,30,38,46,31,39,47,32,40,48],
...
Note that this should only be a demonstration what it should do.
The original array contains only boolean values and has the size of 512x8. In my example, I order only 3 rows with 8 elements into one row but what I really need are respectively 32 rows with 8 elements.
I am really sorry, but after 30 minutes of writing, this is the only description I got of my problem. I hope it is enough.
I think you can achieve your desired result using two reshape operations and a transpose:
x = np.array([[ 1, 2, 3, 4, 5, 6, 7, 8],
[ 9,10,11,12,13,14,15,16],
[17,18,19,20,21,22,23,24],
[25,26,27,28,29,30,31,32],
[33,34,35,36,37,38,39,40],
[41,42,43,44,45,46,47,48]])
y = x.reshape(2, 3, 8).transpose(0, 2, 1).reshape(2, -1)
print(repr(y))
# array([[ 1, 9, 17, 2, 10, 18, 3, 11, 19, 4, 12, 20, 5, 13, 21, 6, 14,
# 22, 7, 15, 23, 8, 16, 24],
# [25, 33, 41, 26, 34, 42, 27, 35, 43, 28, 36, 44, 29, 37, 45, 30, 38,
# 46, 31, 39, 47, 32, 40, 48]])
To break that down a bit:
#hpaulj's first reshape operation gives us this:
x1 = x.reshape(2, 3, 8)
print(repr(x1))
# array([[[ 1, 2, 3, 4, 5, 6, 7, 8],
# [ 9, 10, 11, 12, 13, 14, 15, 16],
# [17, 18, 19, 20, 21, 22, 23, 24]],
# [[25, 26, 27, 28, 29, 30, 31, 32],
# [33, 34, 35, 36, 37, 38, 39, 40],
# [41, 42, 43, 44, 45, 46, 47, 48]]])
print(x1.shape)
# (2, 3, 8)
In order to get the desired output we need to 'collapse' this array along the second dimension (with size 3), then along the third dimension (with size 8).
The easiest way to achieve this sort of thing is to first transpose the
array so that the dimensions you want to collapse along are ordered from first to last:
x2 = x1.transpose(0, 2, 1) # you could also use `x2 = np.rollaxis(x1, 1, 3)`
print(repr(x2))
# array([[[ 1, 9, 17],
# [ 2, 10, 18],
# [ 3, 11, 19],
# [ 4, 12, 20],
# [ 5, 13, 21],
# [ 6, 14, 22],
# [ 7, 15, 23],
# [ 8, 16, 24]],
# [[25, 33, 41],
# [26, 34, 42],
# [27, 35, 43],
# [28, 36, 44],
# [29, 37, 45],
# [30, 38, 46],
# [31, 39, 47],
# [32, 40, 48]]])
print(x2.shape)
# (2, 8, 3)
Finally I can use reshape(2, -1) to collapse the array over the last two dimensions. The -1 causes numpy to infer the appropriate size in the last dimension based on the number of elements in x.
y = x2.reshape(2, -2)
Looks like a starting point is to reshape it, for example
In [49]: x.reshape(2,3,8)
Out[49]:
array([[[ 1, 2, 3, 4, 5, 6, 7, 8],
[ 9, 10, 11, 12, 13, 14, 15, 16],
[17, 18, 19, 20, 21, 22, 23, 24]],
[[25, 26, 27, 28, 29, 30, 31, 32],
[33, 34, 35, 36, 37, 38, 39, 40],
[41, 42, 43, 44, 45, 46, 47, 48]]])
.ravel(order='F') doesn't get it right, so I think we need to swap some axes before flattening. It will need to be a copy.
Using #ali_m's transpose:
In [65]: x1=x.reshape(2,3,8)
In [66]: x1.transpose(0,2,1).flatten()
Out[66]:
array([ 1, 9, 17, 2, 10, 18, 3, 11, 19, 4, 12, 20, 5, 13, 21, 6, 14,
22, 7, 15, 23, 8, 16, 24, 25, 33, 41, 26, 34, 42, 27, 35, 43, 28,
36, 44, 29, 37, 45, 30, 38, 46, 31, 39, 47, 32, 40, 48])
oops - there's an inner layer of nesting that's easy to miss
array([1,9,17,2,10,18,3,11,19,4,12,20,5,13,21,6,14,22,7,15,23,8,16,24],
[25,33,41,26,34,42,27,35,43,28,36,44,29,37,45,30,38,46,31,39,47,32,40,4],
You are missing a [] set. So #ali_m got it right.
I'm tempted to delete this, but my trial and error might be instructive.

Categories