Skip to content

Instantly share code, notes, and snippets.

@morning11pumpkin
Created January 14, 2019 15:06
Show Gist options
  • Save morning11pumpkin/bffe3a4473d163d20e525b33640c737e to your computer and use it in GitHub Desktop.
Save morning11pumpkin/bffe3a4473d163d20e525b33640c737e to your computer and use it in GitHub Desktop.
test
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from PIL import Image"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 0 128 8 136 16 144 24 152]\n",
" [ 32 160 40 168 48 176 56 184]\n",
" [ 64 192 72 200 80 208 88 216]\n",
" [ 96 224 104 232 112 240 120 248]\n",
" [128 0 136 8 144 16 152 24]\n",
" [160 32 168 40 176 48 184 56]\n",
" [192 64 200 72 208 80 216 88]\n",
" [224 96 232 104 240 112 248 120]]\n"
]
}
],
"source": [
"# make array\n",
"a = np.arange(32).astype(np.uint8).reshape(4,8)*8\n",
"b = a+128\n",
"#\n",
"x =a.reshape(-1,)\n",
"y =b.reshape(-1,)\n",
"vs_val = np.vstack((x,y)).reshape(2,-1)\n",
"vs_val = vs_val.T.reshape(8,8)\n",
"print(vs_val)\n",
"\n",
"#make image file\n",
"pilImg = Image.fromarray(np.uint8(vs_val))\n",
"pilImg.save('test20190114.pgm')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 0 1 2 3 4]\n",
" [ 5 6 7 8 9]\n",
" [10 11 12 13 14]\n",
" [15 16 17 18 19]\n",
" [20 21 22 23 24]]\n"
]
}
],
"source": [
"x = np.arange(25).reshape(5,5)\n",
"print(x)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 5 6]\n",
" [10 11]]\n"
]
}
],
"source": [
"print(x[1:3,0:2])"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 1 2]\n",
" [ 6 7]\n",
" [11 12]\n",
" [16 17]\n",
" [21 22]]\n"
]
}
],
"source": [
"print(x[:,1:3])\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 5 6 7 8 9]\n",
" [10 11 12 13 14]]\n"
]
}
],
"source": [
"print(x[1:3,:])"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 5 6 7 8 9]\n",
" [10 11 12 13 14]\n",
" [15 16 17 18 19]\n",
" [20 21 22 23 24]\n",
" [ 0 1 2 3 4]]\n"
]
}
],
"source": [
"xroll = np.roll(x, -1,axis=0)\n",
"print(xroll)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 5 6 7 8 9]\n",
" [10 11 12 13 14]\n",
" [15 16 17 18 19]\n",
" [20 21 22 23 24]\n",
" [ 0 0 0 0 0]]\n"
]
}
],
"source": [
"xroll[5-1:5,:]=0\n",
"print(xroll)\n"
]
},
{
"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.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment