GVKun编程网logo

Python numpy 模块-diagflat() 实例源码(python中numpy模块)

4

在本文中,我们将给您介绍关于Pythonnumpy模块-diagflat()实例源码的详细内容,并且为您解答python中numpy模块的相关问题,此外,我们还将为您提供关于Jupyter中的Nump

在本文中,我们将给您介绍关于Python numpy 模块-diagflat() 实例源码的详细内容,并且为您解答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 模块-diagflat() 实例源码(python中numpy模块)

Python numpy 模块-diagflat() 实例源码(python中numpy模块)

Python numpy 模块,diagflat() 实例源码

我们从Python开源项目中,提取了以下17个代码示例,用于说明如何使用numpy.diagflat()

项目:ESL-Model    作者:littlezz    | 项目源码 | 文件源码
  1. def train(self):
  2. X = self.train_x
  3. y = self.train_y
  4. # include intercept
  5. beta = np.zeros((self.p+1, 1))
  6.  
  7. iter_times = 0
  8. while True:
  9. e_X = np.exp(X @ beta)
  10. # N x 1
  11. self.P = e_X / (1 + e_X)
  12. # W is a vector
  13. self.W = (self.P * (1 - self.P)).flatten()
  14. # X.T * W equal (X.T @ diagflat(W)).diagonal()
  15. beta = beta + self.math.pinv((X.T * self.W) @ X) @ X.T @ (y - self.P)
  16.  
  17. iter_times += 1
  18. if iter_times > self.max_iter:
  19. break
  20.  
  21. self.beta_hat = beta
项目:treecat    作者:posterior    | 项目源码 | 文件源码
  1. def latent_correlation(self):
  2. """Compute correlation matrix among latent features.
  3.  
  4. This computes the generalization of Pearson''s correlation to discrete
  5. data. Let I(X;Y) be the mutual information. Then define correlation as
  6.  
  7. rho(X,Y) = sqrt(1 - exp(-2 I(X;Y)))
  8.  
  9. Returns:
  10. A [V,V]-shaped numpy array of feature-feature correlations.
  11. """
  12. logger.debug(''computing latent correlation'')
  13. V, E, M, R = self._VEMR
  14. edge_probs = self._edge_probs
  15. vert_probs = self._vert_probs
  16. result = np.zeros([V, V], np.float32)
  17. for root in range(V):
  18. messages = np.empty([V, M])
  19. program = make_propagation_program(self._tree.tree_grid, root)
  20. for op, v, v2, e in program:
  21. if op == OP_ROOT:
  22. # Initialize correlation at this node.
  23. messages[v, :, :] = np.diagflat(vert_probs[v, :])
  24. elif op == OP_OUT:
  25. # Propagate correlation outward from parent to v.
  26. trans = edge_probs[e, :]
  27. if v > v2:
  28. trans = trans.T
  29. messages[v, :] = np.dot( #
  30. trans / vert_probs[v2, np.newaxis, :],
  31. messages[v2, :])
  32. for v in range(V):
  33. result[root, v] = correlation(messages[v, :])
  34. return result
项目:ESL-Model    作者:littlezz    | 项目源码 | 文件源码
  1. def train(self):
  2. super().train()
  3. sigma = self.Sigma_hat
  4. D_, U = LA.eigh(sigma)
  5. D = np.diagflat(D_)
  6. self.A = np.power(LA.pinv(D), 0.5) @ U.T
项目:ESL-Model    作者:littlezz    | 项目源码 | 文件源码
  1. def train(self):
  2. super().train()
  3. W = self.Sigma_hat
  4. # prior probabilities (K,1)
  5. Pi = self.Pi
  6. # class centroids (K,p)
  7. Mu = self.Mu
  8. p = self.p
  9. # the number of class
  10. K = self.n_class
  11. # the dimension you want
  12. L = self.L
  13.  
  14. # Mu is (K,p) matrix,Pi is (K,1)
  15. mu = np.sum(Pi * Mu, axis=0)
  16. B = np.zeros((p, p))
  17.  
  18. for k in range(K):
  19. # vector @ vector equal scalar,use vector[:,None] to transform to matrix
  20. # vec[:,None] equal to vec.reshape((1,vec.shape[0]))
  21. B = B + Pi[k]*((Mu[k] - mu)[:, None] @ ((Mu[k] - mu)[None, :]))
  22.  
  23. # Be careful,the `eigh` method get the eigenvalues in ascending,which is opposite to R.
  24. Dw, Uw = LA.eigh(W)
  25. # reverse the Dw_ and Uw
  26. Dw = Dw[::-1]
  27. Uw = np.fliplr(Uw)
  28.  
  29. W_half = self.math.pinv(np.diagflat(Dw**0.5) @ Uw.T)
  30. B_star = W_half.T @ B @ W_half
  31. D_, V = LA.eigh(B_star)
  32.  
  33. # reverse V
  34. V = np.fliplr(V)
  35.  
  36. # overwrite `self.A` so that we can reuse `predict` method define in parent class
  37. self.A = np.zeros((L, p))
  38. for l in range(L):
  39. self.A[l, :] = W_half @ V[:, l]
项目:backtrackbb    作者:BackTrackBB    | 项目源码 | 文件源码
  1. def _update_(U, D, d, lambda_):
  2. """Go from u(n) to u(n+1)."""
  3. I = np.identity(3)
  4.  
  5. m = U.T.dot(d)
  6. p = (I - U.dot(U.T)).dot(d)
  7. p_norm = np.linalg.norm(p)
  8.  
  9. # Make p and m column vectors
  10. p = p[np.newaxis].T
  11. m = m[np.newaxis].T
  12.  
  13. U_left = np.hstack((U, p/p_norm))
  14. Q = np.hstack((lambda_ * D, m))
  15. Q = np.vstack((Q, [0, 0, p_norm]))
  16.  
  17. # SVD
  18. U_right, D_new, V_left = np.linalg.svd(Q)
  19.  
  20. # Get rid of the smallest eigenvalue
  21. D_new = D_new[0:2]
  22. D_new = np.diagflat(D_new)
  23.  
  24. U_right = U_right[:, 0:2]
  25.  
  26. return U_left.dot(U_right), D_new
项目:backtrackbb    作者:BackTrackBB    | 项目源码 | 文件源码
  1. def rosenberger(datax, dataY, dataZ, lambda_):
  2. """
  3. Separate P and non-P wavefield from 3-component data.
  4.  
  5. Return a two set of 3-component traces.
  6. """
  7. # Construct the data matrix
  8. A = np.vstack((dataZ, datax, dataY))
  9.  
  10. # SVD of the first 3 samples:
  11. U, V = np.linalg.svd(A[:, 0:3])
  12.  
  13. # Get rid of the smallest eigenvalue
  14. D = D[0:2]
  15. D = np.diagflat(D)
  16. U = U[:, 0:2]
  17.  
  18. save_U = np.zeros(len(datax))
  19. save_U[0] = abs(U[0, 0])
  20.  
  21. Dp = np.zeros((3, len(datax)))
  22. Ds = np.zeros((3, len(datax)))
  23. Dp[:, 0] = abs(U[0, 0]) * A[:, 2]
  24. Ds[:, 0] = (1 - abs(U[0, 0])) * A[:, 2]
  25.  
  26. # Loop over all the values
  27. for i in range(1, A.shape[1]):
  28. d = A[:, i]
  29. U, D = _update_(U, lambda_)
  30.  
  31. Dp[:, i] = abs(U[0, 0]) * d
  32. Ds[:, i] = (1-abs(U[0, 0])) * d
  33.  
  34. save_U[i] = abs(U[0, 0])
  35.  
  36. return Dp, Ds, save_U
项目:CNNbasedMedicalSegmentation    作者:Brml    | 项目源码 | 文件源码
  1. def eye(n): return diagflat(ones(n))
项目:CNNbasedMedicalSegmentation    作者:Brml    | 项目源码 | 文件源码
  1. def diagflat(a, k=0):
  2. if isinstance(a, garray): return a.diagflat(k)
  3. else: return numpy.diagflat(a,k)
项目:CNNbasedMedicalSegmentation    作者:Brml    | 项目源码 | 文件源码
  1. def diagflat(self, k=0):
  2. if self.ndim!=1: return self.ravel().diagflat(k)
  3. if k!=0: raise NotImplementedError(''k!=0 for garray.diagflat'')
  4. selfSize = self.size
  5. ret = zeros((selfSize, selfSize))
  6. ret.ravel()[:-1].reshape((selfSize-1, selfSize+1))[:, 0] = self[:-1]
  7. if selfSize!=0: ret.ravel()[-1] = self[-1]
  8. return ret
项目:CNNbasedMedicalSegmentation    作者:Brml    | 项目源码 | 文件源码
  1. def diagonal(self):
  2. if self.ndim==1: return self.diagflat()
  3. if self.ndim==2:
  4. if self.shape[0] > self.shape[1]: return self[:self.shape[1]].diagonal()
  5. if self.shape[1] > self.shape[0]: return self[:, :self.shape[0]].diagonal()
  6. return self.ravel()[::self.shape[0]+1]
  7. raise NotImplementedError(''garray.diagonal for arrays with ndim other than 1 or 2.'')
项目:DeepNeuralNet-QSAR    作者:Merck    | 项目源码 | 文件源码
  1. def eye(n): return diagflat(ones(n))
项目:DeepNeuralNet-QSAR    作者:Merck    | 项目源码 | 文件源码
  1. def diagflat(self, 0] = self[:-1]
  2. if selfSize!=0: ret.ravel()[-1] = self[-1]
  3. return ret
项目:DeepNeuralNet-QSAR    作者:Merck    | 项目源码 | 文件源码
  1. def diagonal(self):
  2. if self.ndim==1: return self.diagflat()
  3. if self.ndim==2:
  4. if self.shape[0] > self.shape[1]: return self[:self.shape[1]].diagonal()
  5. if self.shape[1] > self.shape[0]: return self[:, :self.shape[0]].diagonal()
  6. return self.ravel()[::self.shape[0]+1]
  7. raise NotImplementedError(''garray.diagonal for arrays with ndim other than 1 or 2.'')
项目:alchemlyb    作者:alchemistry    | 项目源码 | 文件源码
  1. def fit(self, dHdl):
  2. """
  3. Compute free energy differences between each state by integrating
  4. dHdl across lambda values.
  5.  
  6. Parameters
  7. ----------
  8. dHdl : DataFrame
  9. dHdl[n,k] is the potential energy gradient with respect to lambda
  10. for each configuration n and lambda k.
  11.  
  12. """
  13.  
  14. # sort by state so that rows from same state are in contiguous blocks,
  15. # and adjacent states are next to each other
  16. dHdl = dHdl.sort_index(level=dHdl.index.names[1:])
  17.  
  18. # obtain the mean and variance of the mean for each state
  19. # variance calculation assumes no correlation between points
  20. # used to calculate mean
  21. means = dHdl.mean(level=dHdl.index.names[1:])
  22. variances = np.square(dHdl.sem(level=dHdl.index.names[1:]))
  23.  
  24. # obtain vector of delta lambdas between each state
  25. dl = means.reset_index()[means.index.names[:]].diff().iloc[1:].values
  26.  
  27. # apply trapezoid rule to obtain DF between each adjacent state
  28. deltas = (dl * (means.iloc[:-1].values + means.iloc[1:].values)/2).sum(axis=1)
  29. d_deltas = (dl**2 * (variances.iloc[:-1].values + variances.iloc[1:].values)/4).sum(axis=1)
  30.  
  31. # build matrix of deltas between each state
  32. adelta = np.zeros((len(deltas)+1, len(deltas)+1))
  33. ad_delta = np.zeros_like(adelta)
  34.  
  35. for j in range(len(deltas)):
  36. out = []
  37. dout = []
  38. for i in range(len(deltas) - j):
  39. out.append(deltas[i] + deltas[i+1:i+j+1].sum())
  40. dout.append(d_deltas[i] + d_deltas[i+1:i+j+1].sum())
  41.  
  42. adelta += np.diagflat(np.array(out), k=j+1)
  43. ad_delta += np.diagflat(np.array(dout), k=j+1)
  44.  
  45. # yield standard delta_f_ free energies between each state
  46. self.delta_f_ = pd.DataFrame(adelta - adelta.T,
  47. columns=means.index.values,
  48. index=means.index.values)
  49.  
  50. # yield standard deviation d_delta_f_ between each state
  51. self.d_delta_f_ = pd.DataFrame(np.sqrt(ad_delta + ad_delta.T),
  52. columns=variances.index.values,
  53. index=variances.index.values)
  54.  
  55. self.states_ = means.index.values.tolist()
  56.  
  57. return self
项目:prep    作者:ysyushi    | 项目源码 | 文件源码
  1. def simplex_project(y, infinitesimal):
  2. # 1-D vector version
  3. # D = len(y)
  4. # u = np.sort(y)[::-1]
  5. # x_tmp = (1. - np.cumsum(u)) / np.arange(1,D+1)
  6. # lmd = x_tmp[np.sum(u + x_tmp > 0) - 1]
  7. # return np.maximum(y + lmd,0)
  8.  
  9. n, d = y.shape
  10. x = np.fliplr(np.sort(y, axis=1))
  11. x_tmp = np.dot((np.cumsum(x, axis=1) + (d * infinitesimal - 1.)), np.diagflat(1. / np.arange(1, d + 1)))
  12. lmd = x_tmp[np.arange(n), np.sum(x > x_tmp, axis=1) - 1]
  13. return np.maximum(y - lmd[:, np.newaxis], 0) + infinitesimal
项目:linear-algebra-methods    作者:angellicacardozo    | 项目源码 | 文件源码
  1. def JCB(A,b,N=25,x=None):
  2.  
  3. if x is None:
  4. x = zeros(len(A[0]))
  5.  
  6. D = diag(A)
  7. R = A - diagflat(D)
  8.  
  9. for i in range(N):
  10. x = (b - dot(R,x))/D
  11.  
  12. pprint(x)
  13. return x
项目:DeepNeuralNet-QSAR    作者:Merck    | 项目源码 | 文件源码
  1. def diagflat(a,k)

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):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

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()/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:数组创建 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 模块-diagflat() 实例源码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 ()、数组基本属性的相关信息,请在本站寻找。

本文标签: