在本文中,我们将详细介绍Pythonnumpy模块-PINF实例源码的各个方面,并为您提供关于python中numpy模块的相关解答,同时,我们也将为您带来关于Jupyter中的Numpy在打印时出错
在本文中,我们将详细介绍Python numpy 模块-PINF 实例源码的各个方面,并为您提供关于python中numpy模块的相关解答,同时,我们也将为您带来关于Jupyter 中的 Numpy 在打印时出错(Python 版本 3.8.8):TypeError: 'numpy.ndarray' object is not callable、numpy.random.random & numpy.ndarray.astype & numpy.arange、numpy.ravel()/numpy.flatten()/numpy.squeeze()、Numpy:数组创建 numpy.arrray() , numpy.arange()、np.linspace ()、数组基本属性的有用知识。
本文目录一览:- Python numpy 模块-PINF 实例源码(python中numpy模块)
- Jupyter 中的 Numpy 在打印时出错(Python 版本 3.8.8):TypeError: 'numpy.ndarray' object is not callable
- numpy.random.random & numpy.ndarray.astype & numpy.arange
- numpy.ravel()/numpy.flatten()/numpy.squeeze()
- Numpy:数组创建 numpy.arrray() , numpy.arange()、np.linspace ()、数组基本属性
Python numpy 模块-PINF 实例源码(python中numpy模块)
Python numpy 模块,PINF 实例源码
我们从Python开源项目中,提取了以下23个代码示例,用于说明如何使用numpy.PINF。
- def classify(fn, M, E):
- """
- Classify SAM or SID on a HSI cube
- Can''t be use with normXCorr
- """
- import pysptools.util as util
- width, height, bands = M.shape
- M = util.convert2d(M)
- cmap = np.zeros(M.shape[0])
- for i in range(M.shape[0]):
- T = M[i]
- floor = np.PINF
- k = 0
- for j in range(E.shape[0]):
- R = E[j]
- result = fn(T, R)
- if result < floor:
- floor = result
- k = j
- cmap[i] = k
- return util.convert3d(cmap, width, height)
- def test_adding_bin():
- col = ''mean radius''
- data = cancer_df[col].values
- cib = ConditionalInferenceBinner(''test_dim_{}''.format(col), alpha=0.95)
- cib.fit(data, cancer_target)
- cib.add_bin(-1.0, [0.1, 0.9])
- np.testing.assert_equal(cib.splits, [-1.0, 11.75, 13.079999923706055, 15.039999961853027, 16.84000015258789, np.PINF, np.NaN])
- np.testing.assert_equal(cib.values,
- [[0.1, 0.9],
- [0.02, 0.97999999999999998],
- [0.086956521739130432, 0.91304347826086951],
- [0.2878787878787879, 0.71212121212121215],
- [0.81481481481481477, 0.18518518518518517],
- [0.99152542372881358, 0.0084745762711864406],
- [0.37258347978910367, 0.62741652021089633]])
- def test_recursion_with_nan():
- col = ''mean area''
- data = cancer_df[col].values
- rand_idx = np.linspace(1, 500, 23).astype(int)
- data[rand_idx] = np.NaN
- cib = ConditionalInferenceBinner(''test_dim_{}''.format(col), cancer_target)
- np.testing.assert_equal(cib.splits, [471.29998779296875, 555.0999755859375, 693.7000122070312, 880.2000122070312,
- [[0.030769230769230771, 0.96923076923076923],
- [0.13414634146341464, 0.86585365853658536],
- [0.31730769230769229, 0.68269230769230771],
- [0.83333333333333337, 0.16666666666666666],
- [0.99145299145299148, 0.0085470085470085479],
- [0.2608695652173913, 0.73913043478260865]])
- def test_recursion_with_nan_and_special_value():
- col = ''mean area''
- data = cancer_df[col].values
- rand_idx = np.linspace(1, 23).astype(int)
- data[rand_idx] = np.NaN
- rand_idx_2 = np.linspace(1, 550, 29).astype(int)
- data[rand_idx_2] = -1.0
- cib = ConditionalInferenceBinner(''test_dim_{}''.format(col), alpha=0.95, special_values=[-1.0, np.NaN])
- cib.fit(data, 471.29998779296875, 572.2999877929688, 819.7999877929688,
- [[0.4827586206896552, 0.5172413793103449],
- [0.032432432432432434, 0.9675675675675676],
- [0.14432989690721648, 0.8556701030927835],
- [0.3132530120481928, 0.6867469879518072],
- [0.8205128205128205, 0.1794871794871795],
- [1.0, 0.0],
- [0.23809523809523808, 0.7619047619047619]])
- def _init_shapes_and_data(self, data, labels):
- self.n_features = data.shape[1]
- if isinstance(data, pandas.core.frame.DataFrame):
- self.feature_names = data.columns.tolist()
- data = data.as_matrix()
- if self.feature_names is None:
- self.feature_names = [''feature_{}''.format(dim) for dim in range(self.n_features)]
- if isinstance(labels, pandas.core.series.Series):
- labels = labels.values
- cntr = Counter(labels)
- assert set(cntr.keys()) == {-1, 1}, "Labels must be encoded with -1,1. Cannot contain more classes."
- assert self.n_features is not None, "Number of attributes is None"
- self.shapes = {name: ShapeFunction([np.PINF],
- [0.0],
- name)
- for name in self.feature_names}
- self.initialized = True
- return data, labels
- def _recurse_tree(tree, lst, mdlp, node_id=0, depth=0, min_val=np.NINF, max_val=np.PINF):
- left_child = tree.children_left[node_id]
- right_child = tree.children_right[node_id]
- if left_child == sklearn.tree._tree.TREE_LEAF:
- lst.append(((min_val, max_val), tree.value[node_id].flatten().tolist()))
- return
- else:
- if mdlp and _check_mdlp_stop(tree, node_id):
- lst.append(((min_val, tree.value[node_id].flatten().tolist()))
- return
- _recurse_tree(tree, left_child, depth=depth + 1, min_val=min_val, max_val=tree.threshold[node_id])
- if right_child == sklearn.tree._tree.TREE_LEAF:
- lst.append(((min_val, right_child, min_val=tree.threshold[node_id], max_val=max_val)
- def _clipper(self):
- ''''''
- projects the weights to the feasible set
- :return:
- ''''''
- return tf.assign(self.W, tf.clip_by_value(self.W, 0, np.PINF), name="projector")
- def _create_partition(lst_of_splits):
- return np.append(lst_of_splits, np.PINF)
- def test_func_add_2():
- func1 = ShapeFunction([np.PINF], [0], ''test_1'')
- func2 = ShapeFunction([0, 1, 2], [-1, -2], ''test_1'')
- assert func1 != func2
- func3 = ShapeFunction([0.0, 1.0, 2.0, np.PINF],
- [-1.0, -2.0, ''test_1'')
- assert func1.add(func2).equals(func3)
- def test_recursion():
- binner = tfb.DecisionTreeBinner(''test'', max_leaf_nodes=4)
- binner.fit(data[:, 0], target)
- np.testing.assert_equal(binner.splits, [13.094999313354492, 15.045000076293945, 16.924999237060547, np.NaN])
- np.testing.assert_equal(binner.values, [[0.04905660377358491, 0.9509433962264151],
- [0.2878787878787879, 0.7121212121212122],
- [0.8148148148148148,
- [0.9915254237288136, 0.00847457627118644],
- [0.37258347978910367, 0.62741652021089633]])
- def test_recursion_with_mdlp():
- binner = tfb.DecisionTreeBinner(''test'', mdlp=True)
- binner.fit(data[:, 17.880001068115234,
- [0.8533333333333334, 0.14666666666666667],
- [1.0, 0.62741652021089633]])
- def test_recursion():
- col = ''mean radius''
- data = cancer_df[col].values
- cib = ConditionalInferenceBinner(''test_dim_{}''.format(col), [11.75,
- [[0.02, 0.62741652021089633]])
- def test_adding_bin_with_non_numeric_splits_only():
- cib = ConditionalInferenceBinner(''test'', alpha=0.05)
- cib.splits = [np.PINF, np.NaN]
- cib.values = [[0.1, [0.8, 0.2]]
- cib.is_fit = True
- cib.add_bin(-1.0, [0.3, 0.7])
- np.testing.assert_equal(cib.splits, [[0.3, 0.7], 0.2]])
- def __init__(self, name, **kwargs):
- self.name = name
- self.alpha = kwargs.get(''alpha'', 0.95)
- self.min_samples_split = kwargs.get(''min_samples_split'', 2)
- self.min_samples_leaf = kwargs.get(''min_samples_leaf'', 2)
- self.special_values = kwargs.get(''special_values'', [np.NaN])
- self.num_classes = None
- self._splits = [np.PINF]
- self._values = list()
- self.nodes = list()
- self._is_fit = False
- def __init__(self, **kwargs):
- self.name = name
- self._is_fit = False
- criterion = kwargs.get(''criterion'', ''gini'')
- splitter = kwargs.get(''splitter'', ''best'')
- max_depth = kwargs.get(''max_depth'', None)
- min_samples_split = kwargs.get(''min_samples_split'', 2)
- min_samples_leaf = kwargs.get(''min_samples_leaf'', 1)
- min_weight_fraction_leaf = kwargs.get(''min_weight_fraction_leaf'', 0.0)
- max_features = kwargs.get(''max_features'', None)
- random_state = kwargs.get(''random_state'', None)
- max_leaf_nodes = kwargs.get(''max_leaf_nodes'', None)
- class_weight = kwargs.get(''class_weight'', None)
- presort = kwargs.get(''presort'', False)
- self.mdlp = kwargs.get(''mdlp'', False)
- if self.mdlp:
- criterion = ''entropy''
- max_leaf_nodes = None
- max_depth = None
- self.dtc = DecisionTreeClassifier(criterion=criterion,
- splitter=splitter,
- max_depth=max_depth,
- min_samples_split=min_samples_split,
- min_samples_leaf=min_samples_leaf,
- min_weight_fraction_leaf=min_weight_fraction_leaf,
- max_features=max_features,
- random_state=random_state,
- max_leaf_nodes=max_leaf_nodes,
- class_weight=class_weight,
- presort=presort)
- self._splits = [np.PINF]
- self._values = list()
- def masked_invalid(a, copy=True):
- """
- Mask an array where invalid values occur (NaNs or infs).
- This function is a shortcut to ``masked_where``,with
- `condition` = ~(np.isfinite(a)). Any pre-existing mask is conserved.
- Only applies to arrays with a dtype where NaNs or infs make sense
- (i.e. floating point types),but accepts any array_like object.
- See Also
- --------
- masked_where : Mask where a condition is met.
- Examples
- --------
- >>> import numpy.ma as ma
- >>> a = np.arange(5,dtype=np.float)
- >>> a[2] = np.NaN
- >>> a[3] = np.PINF
- >>> a
- array([ 0.,1.,NaN,Inf,4.])
- >>> ma.masked_invalid(a)
- masked_array(data = [0.0 1.0 -- -- 4.0],
- mask = [False False True True False],
- fill_value=1e+20)
- """
- a = np.array(a, copy=copy, subok=True)
- mask = getattr(a, ''_mask'', None)
- if mask is not None:
- condition = ~(np.isfinite(getdata(a)))
- if mask is not nomask:
- condition |= mask
- cls = type(a)
- else:
- condition = ~(np.isfinite(a))
- cls = MaskedArray
- result = a.view(cls)
- result._mask = condition
- return result
- ###############################################################################
- # Printing options #
- ###############################################################################
- def describe_1d(data, **kwargs):
- leng = len(data) # number of observations in the Series
- count = data.count() # number of non-NaN observations in the Series
- # Replace infinite values with NaNs to avoid issues with
- # histograms later.
- data.replace(to_replace=[np.inf, np.NINF, value=np.nan, inplace=True)
- n_infinite = count - data.count() # number of infinte observations in the Series
- distinct_count = data.nunique(dropna=False) # number of unique elements in the Series
- if count > distinct_count > 1:
- mode = data.mode().iloc[0]
- else:
- mode = data[0]
- results_data = {''count'': count,
- ''distinct_count'': distinct_count,
- ''p_missing'': 1 - count / leng,
- ''n_missing'': leng - count,
- ''p_infinite'': n_infinite / leng,
- ''n_infinite'': n_infinite,
- ''is_unique'': distinct_count == leng,
- ''mode'': mode,
- ''p_unique'': distinct_count / leng}
- try:
- # pandas 0.17 onwards
- results_data[''memorysize''] = data.memory_usage()
- except:
- results_data[''memorysize''] = 0
- result = pd.Series(results_data, name=data.name)
- vartype = get_vartype(data)
- if vartype == ''CONST'':
- result = result.append(describe_constant_1d(data))
- elif vartype == ''BOOL'':
- result = result.append(describe_boolean_1d(data, **kwargs))
- elif vartype == ''NUM'':
- result = result.append(describe_numeric_1d(data, **kwargs))
- elif vartype == ''DATE'':
- result = result.append(describe_date_1d(data, **kwargs))
- elif vartype == ''UNIQUE'':
- result = result.append(describe_unique_1d(data, **kwargs))
- else:
- result = result.append(describe_categorical_1d(data))
- return result
- def masked_invalid(a, None)
- if mask is not None:
- condition = ~(np.isfinite(getdata(a)))
- if mask is not nomask:
- condition |= mask
- cls = type(a)
- else:
- condition = ~(np.isfinite(a))
- cls = MaskedArray
- result = a.view(cls)
- result._mask = condition
- return result
- ###############################################################################
- # Printing options #
- ###############################################################################
- def masked_invalid(a, None)
- if mask is not None:
- condition = ~(np.isfinite(getdata(a)))
- if mask is not nomask:
- condition |= mask
- cls = type(a)
- else:
- condition = ~(np.isfinite(a))
- cls = MaskedArray
- result = a.view(cls)
- result._mask = condition
- return result
- ###############################################################################
- # Printing options #
- ###############################################################################
- def masked_invalid(a, None)
- if mask is not None:
- condition = ~(np.isfinite(getdata(a)))
- if mask is not nomask:
- condition |= mask
- cls = type(a)
- else:
- condition = ~(np.isfinite(a))
- cls = MaskedArray
- result = a.view(cls)
- result._mask = condition
- return result
- ###############################################################################
- # Printing options #
- ###############################################################################
- def masked_invalid(a, None)
- if mask is not None:
- condition = ~(np.isfinite(getdata(a)))
- if mask is not nomask:
- condition |= mask
- cls = type(a)
- else:
- condition = ~(np.isfinite(a))
- cls = MaskedArray
- result = a.view(cls)
- result._mask = condition
- return result
- ###############################################################################
- # Printing options #
- ###############################################################################
- def masked_invalid(a, None)
- if mask is not None:
- condition = ~(np.isfinite(getdata(a)))
- if mask is not nomask:
- condition |= mask
- cls = type(a)
- else:
- condition = ~(np.isfinite(a))
- cls = MaskedArray
- result = a.view(cls)
- result._mask = condition
- return result
- ###############################################################################
- # Printing options #
- ###############################################################################
- def masked_invalid(a, None)
- if mask is not None:
- condition = ~(np.isfinite(getdata(a)))
- if mask is not nomask:
- condition |= mask
- cls = type(a)
- else:
- condition = ~(np.isfinite(a))
- cls = MaskedArray
- result = a.view(cls)
- result._mask = condition
- return result
- ###############################################################################
- # Printing options #
- ###############################################################################
Jupyter 中的 Numpy 在打印时出错(Python 版本 3.8.8):TypeError: 'numpy.ndarray' object is not callable
如何解决Jupyter 中的 Numpy 在打印时出错(Python 版本 3.8.8):TypeError: ''numpy.ndarray'' object is not callable?
晚安, 尝试打印以下内容时,我在 jupyter 中遇到了 numpy 问题,并且得到了一个 错误: 需要注意的是python版本是3.8.8。 我先用 spyder 测试它,它运行正确,它给了我预期的结果
使用 Spyder:
import numpy as np
for i in range (5):
n = np.random.rand ()
print (n)
Results
0.6604903457995978
0.8236300859753154
0.16067650689842816
0.6967868357083673
0.4231597934445466
现在有了 jupyter
import numpy as np
for i in range (5):
n = np.random.rand ()
print (n)
-------------------------------------------------- ------
TypeError Traceback (most recent call last)
<ipython-input-78-0c6a801b3ea9> in <module>
2 for i in range (5):
3 n = np.random.rand ()
----> 4 print (n)
TypeError: ''numpy.ndarray'' object is not callable
感谢您对我如何在 Jupyter 中解决此问题的帮助。
非常感谢您抽出宝贵时间。
阿特,约翰”
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
numpy.random.random & numpy.ndarray.astype & numpy.arange
今天看到这样一句代码:
xb = np.random.random((nb, d)).astype(''float32'') #创建一个二维随机数矩阵(nb行d列)
xb[:, 0] += np.arange(nb) / 1000. #将矩阵第一列的每个数加上一个值
要理解这两句代码需要理解三个函数
1、生成随机数
numpy.random.random(size=None)
size为None时,返回float。
size不为None时,返回numpy.ndarray。例如numpy.random.random((1,2)),返回1行2列的numpy数组
2、对numpy数组中每一个元素进行类型转换
numpy.ndarray.astype(dtype)
返回numpy.ndarray。例如 numpy.array([1, 2, 2.5]).astype(int),返回numpy数组 [1, 2, 2]
3、获取等差数列
numpy.arange([start,]stop,[step,]dtype=None)
功能类似python中自带的range()和numpy中的numpy.linspace
返回numpy数组。例如numpy.arange(3),返回numpy数组[0, 1, 2]
numpy.ravel()/numpy.flatten()/numpy.squeeze()
numpy.ravel(a, order=''C'')
Return a flattened array
numpy.chararray.flatten(order=''C'')
Return a copy of the array collapsed into one dimension
numpy.squeeze(a, axis=None)
Remove single-dimensional entries from the shape of an array.
相同点: 将多维数组 降为 一维数组
不同点:
ravel() 返回的是视图(view),意味着改变元素的值会影响原始数组元素的值;
flatten() 返回的是拷贝,意味着改变元素的值不会影响原始数组;
squeeze()返回的是视图(view),仅仅是将shape中dimension为1的维度去掉;
ravel()示例:
1 import matplotlib.pyplot as plt
2 import numpy as np
3
4 def log_type(name,arr):
5 print("数组{}的大小:{}".format(name,arr.size))
6 print("数组{}的维度:{}".format(name,arr.shape))
7 print("数组{}的维度:{}".format(name,arr.ndim))
8 print("数组{}元素的数据类型:{}".format(name,arr.dtype))
9 #print("数组:{}".format(arr.data))
10
11 a = np.floor(10*np.random.random((3,4)))
12 print(a)
13 log_type(''a'',a)
14
15 a1 = a.ravel()
16 print("a1:{}".format(a1))
17 log_type(''a1'',a1)
18 a1[2] = 100
19
20 print(a)
21 log_type(''a'',a)
flatten()示例
1 import matplotlib.pyplot as plt
2 import numpy as np
3
4 def log_type(name,arr):
5 print("数组{}的大小:{}".format(name,arr.size))
6 print("数组{}的维度:{}".format(name,arr.shape))
7 print("数组{}的维度:{}".format(name,arr.ndim))
8 print("数组{}元素的数据类型:{}".format(name,arr.dtype))
9 #print("数组:{}".format(arr.data))
10
11 a = np.floor(10*np.random.random((3,4)))
12 print(a)
13 log_type(''a'',a)
14
15 a1 = a.flatten()
16 print("修改前a1:{}".format(a1))
17 log_type(''a1'',a1)
18 a1[2] = 100
19 print("修改后a1:{}".format(a1))
20
21 print("a:{}".format(a))
22 log_type(''a'',a)
squeeze()示例:
1. 没有single-dimensional entries的情况
1 import matplotlib.pyplot as plt
2 import numpy as np
3
4 def log_type(name,arr):
5 print("数组{}的大小:{}".format(name,arr.size))
6 print("数组{}的维度:{}".format(name,arr.shape))
7 print("数组{}的维度:{}".format(name,arr.ndim))
8 print("数组{}元素的数据类型:{}".format(name,arr.dtype))
9 #print("数组:{}".format(arr.data))
10
11 a = np.floor(10*np.random.random((3,4)))
12 print(a)
13 log_type(''a'',a)
14
15 a1 = a.squeeze()
16 print("修改前a1:{}".format(a1))
17 log_type(''a1'',a1)
18 a1[2] = 100
19 print("修改后a1:{}".format(a1))
20
21 print("a:{}".format(a))
22 log_type(''a'',a)
从结果中可以看到,当没有single-dimensional entries时,squeeze()返回额数组对象是一个view,而不是copy。
2. 有single-dimentional entries 的情况
1 import matplotlib.pyplot as plt
2 import numpy as np
3
4 def log_type(name,arr):
5 print("数组{}的大小:{}".format(name,arr.size))
6 print("数组{}的维度:{}".format(name,arr.shape))
7 print("数组{}的维度:{}".format(name,arr.ndim))
8 print("数组{}元素的数据类型:{}".format(name,arr.dtype))
9 #print("数组:{}".format(arr.data))
10
11 a = np.floor(10*np.random.random((1,3,4)))
12 print(a)
13 log_type(''a'',a)
14
15 a1 = a.squeeze()
16 print("修改前a1:{}".format(a1))
17 log_type(''a1'',a1)
18 a1[2] = 100
19 print("修改后a1:{}".format(a1))
20
21 print("a:{}".format(a))
22 log_type(''a'',a)
Numpy:数组创建 numpy.arrray() , numpy.arange()、np.linspace ()、数组基本属性
一、Numpy数组创建
part 1:np.linspace(起始值,终止值,元素总个数
import numpy as np
''''''
numpy中的ndarray数组
''''''
ary = np.array([1, 2, 3, 4, 5])
print(ary)
ary = ary * 10
print(ary)
''''''
ndarray对象的创建
''''''
# 创建二维数组
# np.array([[],[],...])
a = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])
print(a)
# np.arange(起始值, 结束值, 步长(默认1))
b = np.arange(1, 10, 1)
print(b)
print("-------------np.zeros(数组元素个数, dtype=''数组元素类型'')-----")
# 创建一维数组:
c = np.zeros(10)
print(c, ''; c.dtype:'', c.dtype)
# 创建二维数组:
print(np.zeros ((3,4)))
print("----------np.ones(数组元素个数, dtype=''数组元素类型'')--------")
# 创建一维数组:
d = np.ones(10, dtype=''int64'')
print(d, ''; d.dtype:'', d.dtype)
# 创建三维数组:
print(np.ones( (2,3,4), dtype=np.int32 ))
# 打印维度
print(np.ones( (2,3,4), dtype=np.int32 ).ndim) # 返回:3(维)
结果图:
part 2 :np.linspace ( 起始值,终止值,元素总个数)
import numpy as np
a = np.arange( 10, 30, 5 )
b = np.arange( 0, 2, 0.3 )
c = np.arange(12).reshape(4,3)
d = np.random.random((2,3)) # 取-1到1之间的随机数,要求设置为诶2行3列的结构
print(a)
print(b)
print(c)
print(d)
print("-----------------")
from numpy import pi
print(np.linspace( 0, 2*pi, 100 ))
print("-------------np.linspace(起始值,终止值,元素总个数)------------------")
print(np.sin(np.linspace( 0, 2*pi, 100 )))
结果图:
二、Numpy的ndarray对象属性:
数组的结构:array.shape
数组的维度:array.ndim
元素的类型:array.dtype
数组元素的个数:array.size
数组的索引(下标):array[0]
''''''
数组的基本属性
''''''
import numpy as np
print("--------------------案例1:------------------------------")
a = np.arange(15).reshape(3, 5)
print(a)
print(a.shape) # 打印数组结构
print(len(a)) # 打印有多少行
print(a.ndim) # 打印维度
print(a.dtype) # 打印a数组内的元素的数据类型
# print(a.dtype.name)
print(a.size) # 打印数组的总元素个数
print("-------------------案例2:---------------------------")
a = np.array([[1, 2, 3], [4, 5, 6]])
print(a)
# 测试数组的基本属性
print(''a.shape:'', a.shape)
print(''a.size:'', a.size)
print(''len(a):'', len(a))
# a.shape = (6, ) # 此格式可将原数组结构变成1行6列的数据结构
# print(a, ''a.shape:'', a.shape)
# 数组元素的索引
ary = np.arange(1, 28)
ary.shape = (3, 3, 3) # 创建三维数组
print("ary.shape:",ary.shape,"\n",ary )
print("-----------------")
print(''ary[0]:'', ary[0])
print(''ary[0][0]:'', ary[0][0])
print(''ary[0][0][0]:'', ary[0][0][0])
print(''ary[0,0,0]:'', ary[0, 0, 0])
print("-----------------")
# 遍历三维数组:遍历出数组里的每个元素
for i in range(ary.shape[0]):
for j in range(ary.shape[1]):
for k in range(ary.shape[2]):
print(ary[i, j, k], end='' '')
结果图:
今天的关于Python numpy 模块-PINF 实例源码和python中numpy模块的分享已经结束,谢谢您的关注,如果想了解更多关于Jupyter 中的 Numpy 在打印时出错(Python 版本 3.8.8):TypeError: 'numpy.ndarray' object is not callable、numpy.random.random & numpy.ndarray.astype & numpy.arange、numpy.ravel()/numpy.flatten()/numpy.squeeze()、Numpy:数组创建 numpy.arrray() , numpy.arange()、np.linspace ()、数组基本属性的相关知识,请在本站进行查询。
本文标签: