Guest User

Untitled

a guest
May 23rd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.74 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": null,
  6. "metadata": {},
  7. "outputs": [],
  8. "source": [
  9. "import numpy as np"
  10. ]
  11. },
  12. {
  13. "cell_type": "markdown",
  14. "metadata": {},
  15. "source": [
  16. "# 1. numpy로 5x5 랜덤 행렬 만들기"
  17. ]
  18. },
  19. {
  20. "cell_type": "code",
  21. "execution_count": 4,
  22. "metadata": {},
  23. "outputs": [
  24. {
  25. "name": "stdout",
  26. "output_type": "stream",
  27. "text": [
  28. "[[0.27256445 0.98917995 0.07114072 0.79926405 0.23969014]\n",
  29. " [0.80478659 0.09748369 0.7503959 0.03095843 0.05164492]\n",
  30. " [0.13663289 0.14028369 0.78751947 0.72739145 0.79974777]\n",
  31. " [0.40468762 0.22329369 0.75673081 0.29983754 0.81019219]\n",
  32. " [0.9097251 0.24756749 0.27425579 0.98508658 0.37157529]]\n"
  33. ]
  34. }
  35. ],
  36. "source": [
  37. "a=np.random.random((5,5))\n",
  38. "print(a)"
  39. ]
  40. },
  41. {
  42. "cell_type": "markdown",
  43. "metadata": {},
  44. "source": [
  45. "# 2.1 1에서 만든 행렬 각 행의 최대값 구하기"
  46. ]
  47. },
  48. {
  49. "cell_type": "code",
  50. "execution_count": 5,
  51. "metadata": {},
  52. "outputs": [
  53. {
  54. "data": {
  55. "text/plain": [
  56. "array([0.98917995, 0.80478659, 0.79974777, 0.81019219, 0.98508658])"
  57. ]
  58. },
  59. "execution_count": 5,
  60. "metadata": {},
  61. "output_type": "execute_result"
  62. }
  63. ],
  64. "source": [
  65. "a.max(1)"
  66. ]
  67. },
  68. {
  69. "cell_type": "markdown",
  70. "metadata": {},
  71. "source": [
  72. "# 2.2 1에서 만든 행렬 각 열의 최대값 구하기"
  73. ]
  74. },
  75. {
  76. "cell_type": "code",
  77. "execution_count": 6,
  78. "metadata": {},
  79. "outputs": [
  80. {
  81. "data": {
  82. "text/plain": [
  83. "array([0.9097251 , 0.98917995, 0.78751947, 0.98508658, 0.81019219])"
  84. ]
  85. },
  86. "execution_count": 6,
  87. "metadata": {},
  88. "output_type": "execute_result"
  89. }
  90. ],
  91. "source": [
  92. "a.max(0)"
  93. ]
  94. },
  95. {
  96. "cell_type": "markdown",
  97. "metadata": {},
  98. "source": [
  99. "# 2.3 1에서 만든 행렬 전체의 최대값 구하기"
  100. ]
  101. },
  102. {
  103. "cell_type": "code",
  104. "execution_count": 7,
  105. "metadata": {},
  106. "outputs": [
  107. {
  108. "data": {
  109. "text/plain": [
  110. "0.9891799457333734"
  111. ]
  112. },
  113. "execution_count": 7,
  114. "metadata": {},
  115. "output_type": "execute_result"
  116. }
  117. ],
  118. "source": [
  119. "a.max()"
  120. ]
  121. },
  122. {
  123. "cell_type": "markdown",
  124. "metadata": {},
  125. "source": [
  126. "# 3. 5x5 에서 가운데 3x3 구하기"
  127. ]
  128. },
  129. {
  130. "cell_type": "code",
  131. "execution_count": 8,
  132. "metadata": {},
  133. "outputs": [
  134. {
  135. "name": "stdout",
  136. "output_type": "stream",
  137. "text": [
  138. "[[0.09748369 0.7503959 0.03095843]\n",
  139. " [0.14028369 0.78751947 0.72739145]\n",
  140. " [0.22329369 0.75673081 0.29983754]]\n"
  141. ]
  142. }
  143. ],
  144. "source": [
  145. "b=a[1:4,1:4]\n",
  146. "print(b)"
  147. ]
  148. },
  149. {
  150. "cell_type": "markdown",
  151. "metadata": {},
  152. "source": [
  153. "# 4.1 1에서 만든 5x5 행렬을 1차원 벡터로 만들기"
  154. ]
  155. },
  156. {
  157. "cell_type": "code",
  158. "execution_count": 12,
  159. "metadata": {
  160. "scrolled": true
  161. },
  162. "outputs": [
  163. {
  164. "name": "stdout",
  165. "output_type": "stream",
  166. "text": [
  167. "[0.27256445 0.98917995 0.07114072 0.79926405 0.23969014 0.80478659\n",
  168. " 0.09748369 0.7503959 0.03095843 0.05164492 0.13663289 0.14028369\n",
  169. " 0.78751947 0.72739145 0.79974777 0.40468762 0.22329369 0.75673081\n",
  170. " 0.29983754 0.81019219 0.9097251 0.24756749 0.27425579 0.98508658\n",
  171. " 0.37157529]\n"
  172. ]
  173. }
  174. ],
  175. "source": [
  176. "b = a.flatten()\n",
  177. "print(b)"
  178. ]
  179. },
  180. {
  181. "cell_type": "markdown",
  182. "metadata": {},
  183. "source": [
  184. "# 4.2 1에서 만든 5x5 행렬을 1x25 행렬로 만들기"
  185. ]
  186. },
  187. {
  188. "cell_type": "code",
  189. "execution_count": 13,
  190. "metadata": {},
  191. "outputs": [
  192. {
  193. "data": {
  194. "text/plain": [
  195. "array([[0.27256445, 0.98917995, 0.07114072, 0.79926405, 0.23969014,\n",
  196. " 0.80478659, 0.09748369, 0.7503959 , 0.03095843, 0.05164492,\n",
  197. " 0.13663289, 0.14028369, 0.78751947, 0.72739145, 0.79974777,\n",
  198. " 0.40468762, 0.22329369, 0.75673081, 0.29983754, 0.81019219,\n",
  199. " 0.9097251 , 0.24756749, 0.27425579, 0.98508658, 0.37157529]])"
  200. ]
  201. },
  202. "execution_count": 13,
  203. "metadata": {},
  204. "output_type": "execute_result"
  205. }
  206. ],
  207. "source": [
  208. "a.reshape(1,25)"
  209. ]
  210. }
  211. ],
  212. "metadata": {
  213. "kernelspec": {
  214. "display_name": "Python 3",
  215. "language": "python",
  216. "name": "python3"
  217. },
  218. "language_info": {
  219. "codemirror_mode": {
  220. "name": "ipython",
  221. "version": 3
  222. },
  223. "file_extension": ".py",
  224. "mimetype": "text/x-python",
  225. "name": "python",
  226. "nbconvert_exporter": "python",
  227. "pygments_lexer": "ipython3",
  228. "version": "3.6.4"
  229. }
  230. },
  231. "nbformat": 4,
  232. "nbformat_minor": 2
  233. }
Add Comment
Please, Sign In to add comment