回答編集履歴
2
編集
answer
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
違いが生じるのは、`repr`で文字列にするか`str`で文字列にするかが違うからですね。
|
2
2
|
|
3
|
-
[組み込み関数 — Python 3.7.4 ドキュメント](https://docs.python.org/ja/3/library/functions.html#repr)
|
3
|
+
[組み込み関数 — Python 3.7.4 ドキュメント (repr)](https://docs.python.org/ja/3/library/functions.html#repr)
|
4
|
-
[組み込み型 — Python 3.7.4 ドキュメント](https://docs.python.org/ja/3/library/stdtypes.html#str)
|
4
|
+
[組み込み型 — Python 3.7.4 ドキュメント (str)](https://docs.python.org/ja/3/library/stdtypes.html#str)
|
5
5
|
|
6
6
|
` name 'array' is not defined`となるのは単にこの名前空間上で`array`が定義されていないからで、具体的には`array`はnumpyモジュール下にありますから、`print(np.array([1, 2, 3]))`とすれば意図通り動きます。あるいは、`from numpy import array`と一行加えておけばそのまま動きます。
|
7
7
|
|
1
追記
answer
CHANGED
@@ -3,6 +3,6 @@
|
|
3
3
|
[組み込み関数 — Python 3.7.4 ドキュメント](https://docs.python.org/ja/3/library/functions.html#repr)
|
4
4
|
[組み込み型 — Python 3.7.4 ドキュメント](https://docs.python.org/ja/3/library/stdtypes.html#str)
|
5
5
|
|
6
|
-
` name 'array' is not defined`となるのは単にこの名前空間上で`array`が定義されていないからで、具体的には`array`はnumpyモジュール下にありますから、`print(np.array([1, 2, 3]))`とすれば意図通り動きます。
|
6
|
+
` name 'array' is not defined`となるのは単にこの名前空間上で`array`が定義されていないからで、具体的には`array`はnumpyモジュール下にありますから、`print(np.array([1, 2, 3]))`とすれば意図通り動きます。あるいは、`from numpy import array`と一行加えておけばそのまま動きます。
|
7
7
|
|
8
8
|
原理的には、`repr`の結果は`__repr__`の実装次第で自由に決められるので、`numpy.array([1, 2, 3])`とかの文字列を返してくれてもいい訳ですが、numpyの開発者は単に結果を`array([1, 2, 3])`とすることを選択した、ということです。
|