0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Python】NumPy配列ndarrayとPythonのリストを相互に変換

Last updated at Posted at 2025-07-18

NumPy配列ndarrayとPythonのリストを相互に変換

import numpy as np

list1 = [0, 1, 2]

v1 = np.array(list1)
print(a_1d)
### [0 1 2]

print(type(v1))
### <class 'numpy.ndarray'>

2次元以上の多次元配列

list2 = [[0, 1, 2], [3, 4, 5]]

v2 = np.array(list2)
print(v2)
#  [0 1 2]
#  [3 4 5]

NumPy配列ndarrayをリストに変換: tolist()

list3 = [[0, 1, 2], [3, 4, 5]]

v3 = np.array(list3)
print(v2)
#  [0 1 2]
#  [3 4 5]

list3_back = v3.tolist()
print(list3_back)
# [[0, 1, 2], [3, 4, 5]]
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?