Numpy(2) : Make Array(2)
One dimensional array : Scala
import numpy as np
a = np.array([1,2,3], dtype=int)
b = np.array([1.1,2.2,3.3], dtype=float)
c = np.array([1,1,0], dtype=bool)
print(a)
print(a.dtype)
print(b)
print(b.dtype)
print(c)
print(c.dtype)
[1 2 3]
int64
[1.1 2.2 3.3]
float64
[ True True False]
bool
You can create an array using np.array({list}, dtype={int/float/bool})
. And it can be returned by .dype
property. If you omit dtype={}
parameter, it automatically recognize the type of list.
Two dimensional array : Matrix
import numpy as np
a = np.array([[1,2,3],[4,5,6],[7,8,9]])
print(a)
[[1 2 3]
[4 5 6]
[7 8 9]]
The list for the multi dimensional array is composed of overlapped lists such as [[1,2,3],[4,5,6],[7,8,9]]
. From that the
Multi dimensional array
import numpy as np
a = np.array([[[1,2],[3,4]],[[5,6],[7,8]],[[9,10],[11,12]]])
print(a)
[[[ 1 2]
[ 3 4]]
[[ 5 6]
[ 7 8]]
[[ 9 10]
[11 12]]]
The list for the multi dimensional array is composed of multi overlapped lists such as [[[1,2],[3,4]],[[5,6],[7,8]],[[9,10],[11,12]]]
. It is printed being seperated by Matrix .
Attribute of array
import numpy as np
a = np.array([[1,2,3],[4,5,6],[7,8,9]])
b = np.array([[[1,2],[3,4]],[[5,6],[7,8]],[[9,10],[11,12]]])
print(a.ndim)
print(a.shape)
print(a.dtype)
print()
print(b.ndim)
print(b.shape)
print(b.dtype)
2
(3, 3)
int64
3
(3, 2, 2)
int64
.ndim
returns the number of dimension of array.
.shape
returns the shape of array.
.dtype
returns the data type of array.
Author And Source
이 문제에 관하여(Numpy(2) : Make Array(2)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@ziwe_ek/Numpy2-Make-Array2저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)