Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
Final_Project_OPEN_SW
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Young Woo Kim
Final_Project_OPEN_SW
Commits
47a6e4a0
Commit
47a6e4a0
authored
4 years ago
by
Young Woo Kim
Browse files
Options
Downloads
Patches
Plain Diff
Update README.md
parent
9e558a2c
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
README.md
+552
-0
552 additions, 0 deletions
README.md
with
552 additions
and
0 deletions
README.md
+
552
−
0
View file @
47a6e4a0
...
@@ -78,4 +78,556 @@ Window의 시작 버튼을 누르고, 명령 프롬프트(CMD)를 관리자 권
...
@@ -78,4 +78,556 @@ Window의 시작 버튼을 누르고, 명령 프롬프트(CMD)를 관리자 권
# Numpy 배워보기
# Numpy 배워보기
```
python
import
numpy
as
np
import
pandas
as
pd
print
(
np
.
__version__
)
print
(
pd
.
__version__
)
```
1.19.3
1.1.5
```
python
#np array 만들기
#여기서부터는 array = 배열로 취급
```
```
python
one
=
[
1
,
2
,
3
,
4
,
5
]
print
(
one
)
ten
=
[
10
,
20
,
30
,
40
,
50
]
print
(
ten
)
type
(
one
)
```
[1, 2, 3, 4, 5]
[10, 20, 30, 40, 50]
list
```
python
onearr
=
np
.
array
(
one
)
tenarr
=
np
.
array
(
ten
)
print
(
onearr
)
print
(
tenarr
)
type
(
onearr
)
```
[1 2 3 4 5]
[10 20 30 40 50]
numpy.ndarray
```
python
onearr
.
dtype
```
dtype('int32')
```
python
onearr
.
shape
```
(5,)
```
python
arr2nd
=
np
.
array
([[
1
,
0
,
0
],[
0
,
1
,
0
],[
0
,
0
,
1
],[
1
,
1
,
1
]])
arr2nd
.
shape
```
(4, 3)
```
python
one
.
dtype
```
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-7-81347d222ef3> in <module>
----> 1 one.dtype
AttributeError: 'list' object has no attribute 'dtype'
```
python
sumarr
=
onearr
+
tenarr
sumlist
=
one
+
ten
print
(
sumarr
)
print
(
sumlist
)
```
[11 22 33 44 55]
[1, 2, 3, 4, 5, 10, 20, 30, 40, 50]
```
python
#기본 배열 만드는 함수 -> 빠르게 배열 만들기
```
```
python
arr1
=
np
.
zeros
(
3
)
arr2
=
np
.
zeros
((
5
,
3
))
print
(
arr1
)
print
(
arr2
)
```
[0. 0. 0.]
[[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]]
```
python
arr1
=
np
.
ones
(
3
)
arr2
=
np
.
ones
((
5
,
3
))
print
(
arr1
)
print
(
arr2
)
```
[1. 1. 1.]
[[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]]
```
python
arr1
=
np
.
identity
(
1
)
arr2
=
np
.
identity
(
2
)
print
(
arr1
)
print
(
arr2
)
```
[[1.]]
[[1. 0.]
[0. 1.]]
```
python
arr1
=
np
.
arange
(
100
)
arr2
=
np
.
arange
(
96
,
100
)
print
(
arr1
)
print
(
arr2
)
```
[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
96 97 98 99]
[96 97 98 99]
```
python
#기본적인 배열의 연산
```
```
python
print
(
onearr
)
print
(
tenarr
)
```
[1 2 3 4 5]
[10 20 30 40 50]
```
python
plus
=
onearr
+
tenarr
minus
=
onearr
-
tenarr
mul
=
onearr
*
tenarr
div
=
onearr
/
tenarr
print
(
plus
)
print
(
minus
)
print
(
mul
)
print
(
div
)
```
[11 22 33 44 55]
[ -9 -18 -27 -36 -45]
[ 10 40 90 160 250]
[0.1 0.1 0.1 0.1 0.1]
```
python
arr1
=
np
.
array
([[
10
,
20
,
30
],
[
100
,
200
,
300
]])
arr2
=
np
.
array
(([
5
,
6
,
7
],
[
5
,
6
,
7
]))
print
(
arr1
+
arr2
)
print
(
arr1
-
arr2
)
```
[[ 15 26 37]
[105 206 307]]
[[ 5 14 23]
[ 95 194 293]]
```
python
arr1
=
np
.
array
([[
10
,
20
],
[
30
,
40
]])
arr2
=
np
.
identity
(
2
)
print
(
arr1
*
arr2
)
```
[[10. 0.]
[ 0. 40.]]
```
python
#numpy에서의 브로드캐스트
#numpy는 브로드 캐스트를 지원합니다. 몰론 두 array가 행이나 열의 길이가 같아야 합니다.
```
```
python
arr1
=
np
.
array
([[
10
,
20
],[
30
,
40
],[
50
,
60
]])
print
(
arr1
)
print
(
arr1
.
shape
)
```
[[10 20]
[30 40]
[50 60]]
(3, 2)
```
python
arr2
=
np
.
array
([
100
,
200
])
arr3
=
np
.
array
([[
100
],
[
200
],
[
300
]])
print
(
arr2
.
shape
)
print
(
arr3
.
shape
)
```
(2,)
(3, 1)
```
python
horizontal
=
arr1
+
arr2
print
(
horizontal
)
vertical
=
arr1
+
arr3
print
(
vertical
)
```
[[110 220]
[130 240]
[150 260]]
[[110 120]
[230 240]
[350 360]]
```
python
difarr
=
np
.
array
([
100
,
200
,
300
,
400
])
sumarr2
=
onearr
+
difarr
print
(
sumarr2
)
```
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-24-3603de6b54e0> in <module>
1 difarr = np.array([100,200,300,400])
----> 2 sumarr2 = onearr + difarr
3 print (sumarr2)
ValueError: operands could not be broadcast together with shapes (5,) (4,)
```
python
#배열의 값 찾기
#파이썬, C언어에서 하는 배열 값 찾기와 비슷하다.
#1차원에서는 기본적으로 1개의 값만 입력하면 되지만, 2차원은 2개의 값을 입력한다.
```
```
python
arr1
=
np
.
arange
(
10
)
print
(
arr1
)
print
(
arr1
[
6
])
print
(
arr1
[
0
])
print
(
arr1
[
3
:
7
])
print
(
arr1
[:
4
])
print
(
arr1
[
6
:])
print
(
arr1
[:])
```
[0 1 2 3 4 5 6 7 8 9]
6
0
[3 4 5 6]
[0 1 2 3]
[6 7 8 9]
[0 1 2 3 4 5 6 7 8 9]
```
python
arr2
=
np
.
array
([[
1
,
2
,
3
],[
4
,
5
,
6
],[
7
,
8
,
9
]])
print
(
arr2
)
print
(
arr2
[
2
,
2
])
print
(
arr2
[
0
,
0
])
print
(
arr2
[
0
,:])
print
(
arr2
[
0
:,
1
:])
print
(
arr2
[:
3
,:
1
])
```
[[1 2 3]
[4 5 6]
[7 8 9]]
9
1
[1 2 3]
[[2 3]
[5 6]
[8 9]]
[[1]
[4]
[7]]
```
python
#numpy의 함수들
#진짜 많다 여기 있는게 다가 아니다
```
```
python
arr1
=
np
.
random
.
random
(
10
)
arr2
=
np
.
random
.
randn
(
10
)
arr3
=
np
.
random
.
rand
(
10
)
arr4
=
np
.
random
.
randint
(
10
)
print
(
arr1
)
print
(
arr2
)
print
(
arr3
)
print
(
arr4
)
```
[0.9446711 0.83497248 0.83201387 0.13935773 0.17415421 0.49383566
0.62534832 0.95301777 0.775304 0.42802872]
[ 0.49760198 0.42642281 -0.17887658 0.97600137 -1.09890443 1.14944642
-1.61367583 0.68313963 -0.69266217 -0.20675362]
[0.45892907 0.79511622 0.23510859 0.83475971 0.61042409 0.98928205
0.04701599 0.47026134 0.10542542 0.6393744 ]
3
```
python
np
.
random
.
rand
(
3
,
10
)
```
array([[0.69049139, 0.33961382, 0.4720473 , 0.05657901, 0.44823818,
0.62798771, 0.18857805, 0.58646854, 0.78296022, 0.23064811],
[0.89095585, 0.56933846, 0.66368549, 0.36591346, 0.78302718,
0.04110933, 0.23313533, 0.3403511 , 0.68102568, 0.99330884],
[0.18974105, 0.01787721, 0.24513353, 0.61273492, 0.82943479,
0.88117367, 0.39032357, 0.85654216, 0.57124692, 0.9269831 ]])
```
python
arr1
=
arr1
*
10
print
(
arr1
)
print
(
np
.
ceil
(
arr1
))
print
(
np
.
floor
(
arr1
))
```
[9.44671104 8.34972483 8.32013866 1.39357733 1.74154213 4.9383566
6.2534832 9.53017769 7.75304001 4.28028724]
[10. 9. 9. 2. 2. 5. 7. 10. 8. 5.]
[9. 8. 8. 1. 1. 4. 6. 9. 7. 4.]
```
python
arr1
=
np
.
array
([[
1
,
2
,
3
],[
4
,
5
,
6
],[
7
,
8
,
9
]])
print
(
np
.
sqrt
(
arr1
))
```
[[1. 1.41421356 1.73205081]
[2. 2.23606798 2.44948974]
[2.64575131 2.82842712 3. ]]
```
python
arr2
=
np
.
array
([[
10
,
-
100
],[
10
,
-
1000
]])
print
(
arr2
)
print
(
np
.
abs
(
arr2
))
```
[[ 10 -100]
[ 10 -1000]]
[[ 10 100]
[ 10 1000]]
```
python
print
(
np
.
exp
(
arr1
))
print
(
np
.
log10
(
arr1
))
```
[[2.71828183e+00 7.38905610e+00 2.00855369e+01]
[5.45981500e+01 1.48413159e+02 4.03428793e+02]
[1.09663316e+03 2.98095799e+03 8.10308393e+03]]
[[0. 0.30103 0.47712125]
[0.60205999 0.69897 0.77815125]
[0.84509804 0.90308999 0.95424251]]
```
python
print
(
np
.
cos
(
arr1
))
```
[[ 0.54030231 -0.41614684 -0.9899925 ]
[-0.65364362 0.28366219 0.96017029]
[ 0.75390225 -0.14550003 -0.91113026]]
```
python
arr3
=
np
.
array
([[
9
,
8
,
7
],[
6
,
5
,
4
],[
3
,
2
,
1
]])
print
(
np
.
maximum
(
arr1
,
arr3
))
print
(
np
.
minimum
(
arr1
,
arr3
))
```
[[9 8 7]
[6 5 6]
[7 8 9]]
[[1 2 3]
[4 5 4]
[3 2 1]]
```
python
#행렬의 정렬
```
```
python
arr1
=
np
.
random
.
rand
(
30
)
arr1
=
arr1
*
100
arr1
=
np
.
floor
(
arr1
)
print
(
arr1
)
arr1
=
arr1
.
astype
(
'
int32
'
)
print
(
arr1
)
print
(
arr1
.
dtype
)
```
[31. 75. 13. 88. 97. 83. 97. 52. 42. 40. 27. 39. 95. 78. 86. 9. 72. 85.
55. 75. 8. 17. 77. 78. 55. 1. 81. 89. 62. 68.]
[31 75 13 88 97 83 97 52 42 40 27 39 95 78 86 9 72 85 55 75 8 17 77 78
55 1 81 89 62 68]
int32
```
python
print
(
np
.
sort
(
arr1
))
print
(
np
.
sort
(
arr1
)[::
-
1
])
```
[ 1 8 9 13 17 27 31 39 40 42 52 55 55 62 68 72 75 75 77 78 78 81 83 85
86 88 89 95 97 97]
[97 97 95 89 88 86 85 83 81 78 78 77 75 75 72 68 62 55 55 52 42 40 39 31
27 17 13 9 8 1]
```
python
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment