ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Python Numpy
    Search: Python Python 2022. 12. 13. 08:08

     

    >>> import numpy as np
    >>>
    >>> a = [1,2,3,4]
    >>> b = np.array(a)
    >>> print(type(a))
    <class 'list'>
    >>> print(type(b))
    <class 'numpy.ndarray'>
    >>> print(a)
    [1, 2, 3, 4]
    >>> print(b)
    [1 2 3 4]
    >>> print(a[0])
    1
    >>> print(b[0])
    1
    >>> print(a[0:3])
    [1, 2, 3]
    >>> print(b[0:3])
    [1 2 3]
    >>> print(a+1)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: can only concatenate list (not "int") to list
    >>> print(b+1)
    [2 3 4 5]
    >>> print(a*2)
    [1, 2, 3, 4, 1, 2, 3, 4]
    >>> print(b*2)
    [2 4 6 8]
    >>> print(a+a)
    [1, 2, 3, 4, 1, 2, 3, 4]
    >>> print(b+b)
    [2 4 6 8]
    >>>

     

    >>> import numpy as np
    >>>
    >>> a = [[1,1,1],[2,2,2],[3,3,3]]
    >>> b = np.array(a)
    >>>
    >>> print(a)
    [[1, 1, 1], [2, 2, 2], [3, 3, 3]]
    >>> print(b)
    [[1 1 1]
     [2 2 2]
     [3 3 3]]
    >>>
    >>> print(b.shape)
    (3, 3)
    >>> print(b * 2)
    [[2 2 2]
     [4 4 4]
     [6 6 6]]
    >>>

     

    Numpy random

     

     

    'Python' 카테고리의 다른 글

    Python Pandas Series 자료형  (0) 2022.12.13
    Numpy zeros  (0) 2022.12.13
    Numpy sqrt, log, max  (0) 2022.12.13
    Numpy random  (0) 2022.12.13
    Python Re - group  (0) 2022.12.13
    Python Re - match, search 예제  (0) 2022.12.13
    Python, on Windows 7  (0) 2022.11.28
    Twisted (networking engine)  (0) 2022.08.17

    댓글