You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

222 lines
4.9 KiB

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The original array is:\n",
"[[ 0 1 2 3 4 5 6 7]\n",
" [ 8 9 10 11 12 13 14 15]\n",
" [16 17 18 19 20 21 22 23]\n",
" [24 25 26 27 28 29 30 31]\n",
" [32 33 34 35 36 37 38 39]\n",
" [40 41 42 43 44 45 46 47]\n",
" [48 49 50 51 52 53 54 55]]\n",
"\n",
"\n",
"The transposed array is:\n",
"[[ 0 8 16 24 32 40 48]\n",
" [ 1 9 17 25 33 41 49]\n",
" [ 2 10 18 26 34 42 50]\n",
" [ 3 11 19 27 35 43 51]\n",
" [ 4 12 20 28 36 44 52]\n",
" [ 5 13 21 29 37 45 53]\n",
" [ 6 14 22 30 38 46 54]\n",
" [ 7 15 23 31 39 47 55]]\n"
]
}
],
"source": [
"import numpy as np \n",
"a = np.arange(56).reshape(7,8) \n",
"\n",
"print('The original array is:')\n",
"print(a)\n",
"print('\\n') \n",
"\n",
"print('The transposed array is:')\n",
"print(np.transpose(a))"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0, 1, 2, 3, 4, 5, 6, 7],\n",
" [ 8, 9, 10, 11, 12, 13, 14, 15],\n",
" [16, 17, 18, 19, 20, 21, 22, 23],\n",
" [24, 25, 26, 27, 28, 29, 30, 31],\n",
" [32, 33, 34, 35, 36, 37, 38, 39],\n",
" [40, 41, 42, 43, 44, 45, 46, 47],\n",
" [48, 49, 50, 51, 52, 53, 54, 55]])"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"27"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 2D Arrays indexing\n",
"# array[line, column]\n",
"a[3,3]"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0, 1, 2, 3, 4, 5, 6, 7],\n",
" [ 8, 9, 10, 11, 12, 13, 14, 15],\n",
" [16, 17, 18, 19, 20, 21, 22, 23],\n",
" [24, 25, 26, 27, 28, 29, 30, 31],\n",
" [32, 33, 34, 35, 36, 37, 38, 39],\n",
" [40, 41, 42, 43, 44, 45, 46, 47],\n",
" [48, 49, 50, 51, 52, 53, 54, 55]])"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 2D Arrays slicing\n",
"# array[start:stop:step]\n",
"a[::3] # each 3 lines from the first"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0, 1, 2, 3, 4, 5, 6, 7],\n",
" [ 8, 9, 10, 11, 12, 13, 14, 15],\n",
" [16, 17, 18, 19, 20, 21, 22, 23],\n",
" [24, 25, 26, 27, 28, 29, 30, 31],\n",
" [32, 33, 34, 35, 36, 37, 38, 39],\n",
" [40, 41, 42, 43, 44, 45, 46, 47],\n",
" [48, 49, 50, 51, 52, 53, 54, 55]])"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a[0:7:1]"
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[24, 25, 26, 27, 28, 29, 30, 31],\n",
" [32, 33, 34, 35, 36, 37, 38, 39],\n",
" [40, 41, 42, 43, 44, 45, 46, 47],\n",
" [48, 49, 50, 51, 52, 53, 54, 55]])"
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a[3::]"
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0. , 0.125, 0.25 , 0.375, 0.5 , 0.625, 0.75 , 0.875, 1. ,\n",
" 1.125, 1.25 ])"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"clevs = np.arange(0,1.26,0.125)\n",
"clevs"
]
},
{
"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.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}