관리-도구
편집 파일: index_tricks.cpython-37.pyc
B ��Fd1h � @ s� d dl mZmZmZ d dlZd dlZd dlm mZ d dlm Z mZmZm Z mZmZ d dlmZmZ ddlmZ d dlmZ ddlmZ d dlmZmZ d d lmZ d ddd ddddddddddgZdd� ZG dd� de�Z e dd�Z!e dd�Z"de!_#de"_#G dd� de�Z$G d d!� d!e$�Z%e%� Z&G d"d#� d#e$�Z'e'� Z(G d$d� de�Z)G d%d� de�Z*G d&d'� d'e�Z+e+dd(�Z,e+dd(�Z-d-d)d�Z.d.d+d�Z/d,d� Z0dS )/� )�division�absolute_import�print_functionN)�asarray� ScalarType�array�alltrue�cumprod�arange)�find_common_type� issubdtype� )� function_base)�diff)�ravel_multi_index� unravel_index)� as_stridedr r �mgrid�ogrid�r_�c_�s_� index_exp�ix_�ndenumerate�ndindex� fill_diagonal�diag_indices�diag_indices_fromc G s� g }t | �}x�t| �D ]�\}}t|�}|jdkr8td��|jdkrN|�tj�}t |j tj�rf|�� \}|� d| |jf d|| d �}|�|� qW t|�S )a5 Construct an open mesh from multiple sequences. This function takes N 1-D sequences and returns N outputs with N dimensions each, such that the shape is 1 in all but one dimension and the dimension with the non-unit shape value cycles through all N dimensions. Using `ix_` one can quickly construct index arrays that will index the cross product. ``a[np.ix_([1,3],[2,5])]`` returns the array ``[[a[1,2] a[1,5]], [a[3,2] a[3,5]]]``. Parameters ---------- args : 1-D sequences Each sequence should be of integer or boolean type. Boolean sequences will be interpreted as boolean masks for the corresponding dimension (equivalent to passing in ``np.nonzero(boolean_sequence)``). Returns ------- out : tuple of ndarrays N arrays with N dimensions each, with N the number of input sequences. Together these arrays form an open mesh. See Also -------- ogrid, mgrid, meshgrid Examples -------- >>> a = np.arange(10).reshape(2, 5) >>> a array([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]) >>> ixgrid = np.ix_([0, 1], [2, 4]) >>> ixgrid (array([[0], [1]]), array([[2, 4]])) >>> ixgrid[0].shape, ixgrid[1].shape ((2, 1), (1, 2)) >>> a[ixgrid] array([[2, 4], [7, 9]]) >>> ixgrid = np.ix_([True, True], [2, 4]) >>> a[ixgrid] array([[2, 4], [7, 9]]) >>> ixgrid = np.ix_([True, True], [False, False, True, False, True]) >>> a[ixgrid] array([[2, 4], [7, 9]]) r z!Cross index must be 1 dimensionalr )r )�len� enumerater �ndim� ValueError�size�astype�_nxZintpr �dtypeZbool_ZnonzeroZreshape�append�tuple)�args�outZnd�k�new� r- �I/opt/alt/python37/lib64/python3.7/site-packages/numpy/lib/index_tricks.pyr s 9 &c @ s* e Zd ZdZd dd�Zdd� Zdd� Zd S )�nd_grida Construct a multi-dimensional "meshgrid". ``grid = nd_grid()`` creates an instance which will return a mesh-grid when indexed. The dimension and number of the output arrays are equal to the number of indexing dimensions. If the step length is not a complex number, then the stop is not inclusive. However, if the step length is a **complex number** (e.g. 5j), then the integer part of its magnitude is interpreted as specifying the number of points to create between the start and stop values, where the stop value **is inclusive**. If instantiated with an argument of ``sparse=True``, the mesh-grid is open (or not fleshed out) so that only one-dimension of each returned argument is greater than 1. Parameters ---------- sparse : bool, optional Whether the grid is sparse or not. Default is False. Notes ----- Two instances of `nd_grid` are made available in the NumPy namespace, `mgrid` and `ogrid`:: mgrid = nd_grid(sparse=False) ogrid = nd_grid(sparse=True) Users should use these pre-defined instances instead of using `nd_grid` directly. Examples -------- >>> mgrid = np.lib.index_tricks.nd_grid() >>> mgrid[0:5,0:5] array([[[0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [4, 4, 4, 4, 4]], [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]]]) >>> mgrid[-1:1:5j] array([-1. , -0.5, 0. , 0.5, 1. ]) >>> ogrid = np.lib.index_tricks.nd_grid(sparse=True) >>> ogrid[0:5,0:5] [array([[0], [1], [2], [3], [4]]), array([[0, 1, 2, 3, 4]])] Fc C s || _ d S )N)�sparse)�selfr0 r- r- r. �__init__� s znd_grid.__init__c C s� �y�g }t }x�tt|��D ]�}|| j}|| j}|d kr>d}|d krJd}t|t�rl|�t t|��� t }n&|�t t �|| j| |d ��� t|t �s�t|t �s�t|| jt �rt }qW | j r�dd� t||ft|� �D �}nt�||�}x�tt|��D ]�}|| j}|| j}|d k�r$d}|d k�r2d}t|t��rnt t|��}|dk�rn|| j| t |d � }|| | | ||<