IPython

IPython是一個功能強大的交互式shell
適合進行交互式數(shù)據(jù)可視化和GUI相關(guān)應(yīng)用

IPython的疆导?

變量前或后增加?將顯示一些通用信息包括函數(shù)對應(yīng)的源代碼

In [1]: import numpy as np

In [2]: a=np.arange(10)

In [3]: a
Out[3]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

In [4]: a?
Type:            ndarray
String form:     [0 1 2 3 4 5 6 7 8 9]
Length:          10
File:            c:\users\summer\anaconda3\lib\site-packages\numpy\__init__.py
Docstring:       <no docstring>
Class docstring:
ndarray(shape, dtype=float, buffer=None, offset=0,
        strides=None, order=None)

An array object represents a multidimensional, homogeneous array
of fixed-size items.  An associated data-type object describes the
format of each element in the array (its byte-order, how many bytes it
occupies in memory, whether it is an integer, a floating point number,
or something else, etc.)

Arrays should be constructed using `array`, `zeros` or `empty` (refer
to the See Also section below).  The parameters given here refer to
a low-level method (`ndarray(...)`) for instantiating an array.

For more information, refer to the `numpy` module and examine the
methods and attributes of an array.

Parameters
----------
(for the __new__ method; see Notes below)

shape : tuple of ints
    Shape of created array.
dtype : data-type, optional
    Any object that can be interpreted as a numpy data type.
buffer : object exposing buffer interface, optional
    Used to fill the array with data.
offset : int, optional
    Offset of array data in buffer.
strides : tuple of ints, optional
    Strides of data in memory.
order : {'C', 'F'}, optional
    Row-major (C-style) or column-major (Fortran-style) order.

Attributes
----------
T : ndarray
    Transpose of the array.
data : buffer
    The array's elements, in memory.
dtype : dtype object
    Describes the format of the elements in the array.
flags : dict
    Dictionary containing information related to memory use, e.g.,
    'C_CONTIGUOUS', 'OWNDATA', 'WRITEABLE', etc.
flat : numpy.flatiter object
    Flattened version of the array as an iterator.  The iterator
    allows assignments, e.g., ``x.flat = 3`` (See `ndarray.flat` for
    assignment examples; TODO).
imag : ndarray
    Imaginary part of the array.
real : ndarray
    Real part of the array.
size : int
    Number of elements in the array.
itemsize : int
    The memory use of each array element in bytes.
nbytes : int
    The total number of bytes required to store the array data,
    i.e., ``itemsize * size``.
ndim : int
    The array's number of dimensions.
shape : tuple of ints
    Shape of the array.
strides : tuple of ints
    The step-size required to move from one element to the next in
    memory. For example, a contiguous ``(3, 4)`` array of type
    ``int16`` in C-order has strides ``(8, 2)``.  This implies that
    to move from element to element in memory requires jumps of 2 bytes.
    To move from row-to-row, one needs to jump 8 bytes at a time
    (``2 * 4``).
ctypes : ctypes object
    Class containing properties of the array needed for interaction
    with ctypes.
base : ndarray
    If the array is a view into another array, that array is its `base`
    (unless that array is also a view).  The `base` array is where the
    array data is actually stored.

See Also
--------
array : Construct an array.
zeros : Create an array, each element of which is zero.
empty : Create an array, but leave its allocated memory unchanged (i.e.,
        it contains "garbage").
dtype : Create a data-type.

Notes
-----
There are two modes of creating an array using ``__new__``:

1. If `buffer` is None, then only `shape`, `dtype`, and `order`
   are used.
2. If `buffer` is an object exposing the buffer interface, then
   all keywords are interpreted.

No ``__init__`` method is needed because the array is fully initialized
after the ``__new__`` method.

Examples
--------
These examples illustrate the low-level `ndarray` constructor.  Refer
to the `See Also` section above for easier ways of constructing an
ndarray.

First mode, `buffer` is None:

>>> np.ndarray(shape=(2,2), dtype=float, order='F')
array([[ -1.13698227e+002,   4.25087011e-303],
       [  2.88528414e-306,   3.27025015e-309]])         #random

Second mode:

>>> np.ndarray((2,), buffer=np.array([1,2,3]),
...            offset=np.int_().itemsize,
...            dtype=int) # offset = 1*itemsize, i.e. skip first element
array([2, 3])

IPython的%run命令

%run用于運行.py程序
注意:%run在一個空的命名空間執(zhí)行%

IPython的%魔術(shù)命令

常用命令 說明
%magic 顯示所有魔術(shù)命令
%hist IPython命令的輸入歷史
%pdb 異常發(fā)生后自動進入調(diào)試器
%reset 刪除當(dāng)前命名空間中的全部變量或名稱
%who 顯示Ipython當(dāng)前命名空間中已經(jīng)定義的變量
%time statement 給出代碼的執(zhí)行時間, statement表示一段代碼
%timeit statement 多次執(zhí)行代碼诅挑,計算綜合平均執(zhí)行時間
In [6]: a=np.random.randn(1000,1000)

In [7]: %timeit np.dot(a,a)
32.5 ms ± 3.64 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

In [8]: %who
a        np      

In [9]: %hist
import numpy as np
a=np.arange(10)
a
a?
%magic
a=np.random.randn(1000,1000)
%timeit np.dot(a,a)
%who
%hist

In [10]: 
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末庐舟,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,451評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件镜硕,死亡現(xiàn)場離奇詭異,居然都是意外死亡纯赎,警方通過查閱死者的電腦和手機谦疾,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,172評論 3 394
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來犬金,“玉大人念恍,你說我怎么就攤上這事⊥砬辏” “怎么了峰伙?”我有些...
    開封第一講書人閱讀 164,782評論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長该默。 經(jīng)常有香客問我瞳氓,道長,這世上最難降的妖魔是什么栓袖? 我笑而不...
    開封第一講書人閱讀 58,709評論 1 294
  • 正文 為了忘掉前任匣摘,我火速辦了婚禮店诗,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘音榜。我一直安慰自己庞瘸,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,733評論 6 392
  • 文/花漫 我一把揭開白布赠叼。 她就那樣靜靜地躺著擦囊,像睡著了一般。 火紅的嫁衣襯著肌膚如雪嘴办。 梳的紋絲不亂的頭發(fā)上瞬场,一...
    開封第一講書人閱讀 51,578評論 1 305
  • 那天,我揣著相機與錄音涧郊,去河邊找鬼贯被。 笑死,一個胖子當(dāng)著我的面吹牛底燎,可吹牛的內(nèi)容都是我干的刃榨。 我是一名探鬼主播,決...
    沈念sama閱讀 40,320評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼双仍,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了桌吃?” 一聲冷哼從身側(cè)響起朱沃,我...
    開封第一講書人閱讀 39,241評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎茅诱,沒想到半個月后逗物,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,686評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡瑟俭,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,878評論 3 336
  • 正文 我和宋清朗相戀三年翎卓,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片摆寄。...
    茶點故事閱讀 39,992評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡失暴,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出微饥,到底是詐尸還是另有隱情逗扒,我是刑警寧澤,帶...
    沈念sama閱讀 35,715評論 5 346
  • 正文 年R本政府宣布欠橘,位于F島的核電站矩肩,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏肃续。R本人自食惡果不足惜黍檩,卻給世界環(huán)境...
    茶點故事閱讀 41,336評論 3 330
  • 文/蒙蒙 一叉袍、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧刽酱,春花似錦喳逛、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,912評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至衍慎,卻和暖如春转唉,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背稳捆。 一陣腳步聲響...
    開封第一講書人閱讀 33,040評論 1 270
  • 我被黑心中介騙來泰國打工赠法, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人乔夯。 一個月前我還...
    沈念sama閱讀 48,173評論 3 370
  • 正文 我出身青樓砖织,卻偏偏與公主長得像,于是被迫代替她去往敵國和親末荐。 傳聞我的和親對象是個殘疾皇子侧纯,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,947評論 2 355

推薦閱讀更多精彩內(nèi)容