2016年12月19日月曜日

開発環境

Data Visualization with Python and JavaScript (Kyran Dale 著、O'Reilly Media;)のPart3.(Cleaning and Exploring Data with Pandas)、Chapter 7.(Introduction to NumPy)、The NumPy Array(Array Indexing and Slicing)にミスがあるっぽいから報告、提出してみた。

コード(Emacs)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import numpy as np

try:
    a = np.array(arange(8))
except Exception as err:
    print(err)

a = np.arange(8)
a.shape = (2, 2, 2)

print(a)


print(a[1], a[1, :], a[1, :, :], sep='\n')
print(a[1] == a[1, :])
print(a[1, :] == a[1, :, :])
print(a[1, :, :] == a[1])

try:
    print(a[1] == a[1, :] == a[1, :, :])
except Exception as err:
    print(err)

print(a[..., 0] == a[:, :, 0])

入出力結果(Terminal, IPython)

$ ./sample.py 
name 'arange' is not defined
[[[0 1]
  [2 3]]

 [[4 5]
  [6 7]]]
[[4 5]
 [6 7]]
[[4 5]
 [6 7]]
[[4 5]
 [6 7]]
[[ True  True]
 [ True  True]]
[[ True  True]
 [ True  True]]
[[ True  True]
 [ True  True]]
The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
[[ True  True]
 [ True  True]]
$ 

0 コメント:

コメントを投稿