Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "import numpy as np"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# 1. numpy로 5x5 랜덤 행렬 만들기"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "[[0.27256445 0.98917995 0.07114072 0.79926405 0.23969014]\n",
- " [0.80478659 0.09748369 0.7503959 0.03095843 0.05164492]\n",
- " [0.13663289 0.14028369 0.78751947 0.72739145 0.79974777]\n",
- " [0.40468762 0.22329369 0.75673081 0.29983754 0.81019219]\n",
- " [0.9097251 0.24756749 0.27425579 0.98508658 0.37157529]]\n"
- ]
- }
- ],
- "source": [
- "a=np.random.random((5,5))\n",
- "print(a)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# 2.1 1에서 만든 행렬 각 행의 최대값 구하기"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "array([0.98917995, 0.80478659, 0.79974777, 0.81019219, 0.98508658])"
- ]
- },
- "execution_count": 5,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "a.max(1)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# 2.2 1에서 만든 행렬 각 열의 최대값 구하기"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "array([0.9097251 , 0.98917995, 0.78751947, 0.98508658, 0.81019219])"
- ]
- },
- "execution_count": 6,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "a.max(0)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# 2.3 1에서 만든 행렬 전체의 최대값 구하기"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "0.9891799457333734"
- ]
- },
- "execution_count": 7,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "a.max()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# 3. 5x5 에서 가운데 3x3 구하기"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "[[0.09748369 0.7503959 0.03095843]\n",
- " [0.14028369 0.78751947 0.72739145]\n",
- " [0.22329369 0.75673081 0.29983754]]\n"
- ]
- }
- ],
- "source": [
- "b=a[1:4,1:4]\n",
- "print(b)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# 4.1 1에서 만든 5x5 행렬을 1차원 벡터로 만들기"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 12,
- "metadata": {
- "scrolled": true
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "[0.27256445 0.98917995 0.07114072 0.79926405 0.23969014 0.80478659\n",
- " 0.09748369 0.7503959 0.03095843 0.05164492 0.13663289 0.14028369\n",
- " 0.78751947 0.72739145 0.79974777 0.40468762 0.22329369 0.75673081\n",
- " 0.29983754 0.81019219 0.9097251 0.24756749 0.27425579 0.98508658\n",
- " 0.37157529]\n"
- ]
- }
- ],
- "source": [
- "b = a.flatten()\n",
- "print(b)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# 4.2 1에서 만든 5x5 행렬을 1x25 행렬로 만들기"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 13,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "array([[0.27256445, 0.98917995, 0.07114072, 0.79926405, 0.23969014,\n",
- " 0.80478659, 0.09748369, 0.7503959 , 0.03095843, 0.05164492,\n",
- " 0.13663289, 0.14028369, 0.78751947, 0.72739145, 0.79974777,\n",
- " 0.40468762, 0.22329369, 0.75673081, 0.29983754, 0.81019219,\n",
- " 0.9097251 , 0.24756749, 0.27425579, 0.98508658, 0.37157529]])"
- ]
- },
- "execution_count": 13,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "a.reshape(1,25)"
- ]
- }
- ],
- "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.4"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
Add Comment
Please, Sign In to add comment