2
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?

More than 3 years have passed since last update.

Numpyのarrayとasarrayについて

Last updated at Posted at 2020-04-18

Python1年生を学習中にnumpy.asarrayという表記が出てきたので調べてみた。
調べるとnumpy.arrayというのも出てきたので違いを解説する

※Numpyには配列を高速に扱うためにndarrayクラスがあり、
ndarray配列を生成するためにnp.array()を用いる。

np.array(リスト)

import numpy as np
print(np.array([1, 2, 3]))

>>>出力結果
>>>[1 2 3]

続いて

np.asarray(リスト)

import numpy as np
print(np.asarray([1, 2, 3]))

>>>出力結果
>>>[1 2 3]

では何が違うのか?

#ここが違う
##np.array

copy_array[0] = 100
print(x)
print(copy_array)

>>>[1 2 3]
>>>[100 2 3]

##np.asarray

copy_asarray[0] = 100
print(x)
print(copy_asarray)

>>>[100 2 3]
>>>[100 2 3]

結論としてはasarrayはコピー前の物も引き継いでいる。

2
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
2
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?