Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
leomariga committed Sep 10, 2019
1 parent 91a1233 commit 854287e
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .ipynb_checkpoints/keras_list_string-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 2
}
133 changes: 133 additions & 0 deletions keras_list_string.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 79,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[[4, [22, 16, 11, 33], 24],\n",
" [4, [12, 33, 87, 17], 14],\n",
" [3, [92, 407, 25, 27], 34]]"
]
},
"execution_count": 79,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import numpy as np\n",
"a = [\n",
" [4, [22, 16, 11, 33], 24],\n",
" [4, [12, 33, 87, 17], 14],\n",
" [3, [92, 407, 25, 27], 34]\n",
"]\n",
"a"
]
},
{
"cell_type": "code",
"execution_count": 80,
"metadata": {},
"outputs": [],
"source": [
"column1 = list(zip(*a))[1]"
]
},
{
"cell_type": "code",
"execution_count": 88,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['22|16|11|33', '12|33|87|17', '92|407|25|27']"
]
},
"execution_count": 88,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"newColumn1 = ['|'.join(str(e) for e in row) for row in column1]\n",
"newColumn1"
]
},
{
"cell_type": "code",
"execution_count": 89,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[(4, 4, 3), ['22|16|11|33', '12|33|87|17', '92|407|25|27'], (24, 14, 34)]"
]
},
"execution_count": 89,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"b = list(zip(*a))\n",
"b[1] = newColumn1\n",
"b"
]
},
{
"cell_type": "code",
"execution_count": 90,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[(4, '22|16|11|33', 24), (4, '12|33|87|17', 14), (3, '92|407|25|27', 34)]"
]
},
"execution_count": 90,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a2 = list(zip(*b))\n",
"a2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
20 changes: 20 additions & 0 deletions keras_list_string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Imagine you have a output layer like this:
a = [
[4, [22, 16, 11, 33], 24],
[4, [12, 33, 87, 17], 14],
[3, [92, 407, 25, 27], 34]
]

# "transpose" the list and get the second element
column1 = list(zip(*a))[1]

# Join all elements with |
newColumn1 = ['|'.join(str(e) for e in row) for row in column1]

# Put back the modified column
b = list(zip(*a))
b[1] = newColumn1

# "Untranspose" your list
a2 = list(zip(*b))

0 comments on commit 854287e

Please sign in to comment.