(3.23)
1.有关np.random.randn;np.random.rand;np.random.randint的作用
np.random.randn():返回一个或一组服从标准正态分布的随机样本值。
np.random.rand():返回一个或一组服从“0~1”均匀分布的随机样本值。随机样本取值范围是[0,1),不包括1。
np.random.randint():输出一个范围内的整数,,它的输入为 low最小值 high最大值 size数组维度大小 dtype数据类型(默认的数据类型是np.int)。
2.np.linalg.norm
使用到的函数参数
np.linalg.norm(x, ord=None, axis=None, keepdims=False)
x指传入的数据,矩阵
ord是指
axis和keepdims之前在np.sum()中都有使用,axis=1时表示按行向量处理,求多个行向量的范数;axis=0表示按列向量处理,求多个列向量的范数。
keepdims表示是否保持矩阵的二维特性“True”表示保持矩阵的二维特性,“False”相反。
要遇到以下这种问题 大多数都是维度的事情,这时我们要在所给的包中找到报错的地方,就比如说这里就找到了在以下加星号之间的位置
只要把 c = y 改为 c = np.squeeze(y)就好,下次出现问题可以尝试着把一个值换成np.squeeze()试试,没准就跑通了
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
D:\anaconda\lib\site-packages\matplotlib\colors.py in to_rgba(c, alpha)
165 try:
--> 166 rgba = _colors_full_map.cache[c, alpha]
167 except (KeyError, TypeError): # Not in cache, or unhashable.
TypeError: unhashable type: 'numpy.ndarray'
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
D:\anaconda\lib\site-packages\matplotlib\axes\_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)
4273 # must be acceptable as PathCollection facecolors
-> 4274 colors = mcolors.to_rgba_array(c)
4275 except ValueError:
D:\anaconda\lib\site-packages\matplotlib\colors.py in to_rgba_array(c, alpha)
266 for i, cc in enumerate(c):
--> 267 result[i] = to_rgba(cc, alpha)
268 return result
D:\anaconda\lib\site-packages\matplotlib\colors.py in to_rgba(c, alpha)
167 except (KeyError, TypeError): # Not in cache, or unhashable.
--> 168 rgba = _to_rgba_no_colorcycle(c, alpha)
169 try:
D:\anaconda\lib\site-packages\matplotlib\colors.py in _to_rgba_no_colorcycle(c, alpha)
222 if len(c) not in [3, 4]:
--> 223 raise ValueError("RGBA sequence should have length 3 or 4")
224 if len(c) == 3 and alpha is None:
ValueError: RGBA sequence should have length 3 or 4
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
<ipython-input-8-fa950cac67af> in <module>()
2 axes.set_xlim([-1.5,1.5])
3 axes.set_ylim([-1.5,1.5])
----> 4 init_utils.plot_decision_boundary(lambda x:init_utils.predict_dec(parameters,x.T),train_X,train_Y)
***************************************************************************
E:\jupyter notebook\【吴恩达课后编程作业】Course+2+-+改善深层神经网络+-+第一周作业%281%262%263%29\init_utils.py in plot_decision_boundary(model, X, y)
207 plt.ylabel('x2')
208 plt.xlabel('x1')
--> 209 plt.scatter(X[0, :], X[1, :], c=y, cmap=plt.cm.Spectral)
210 plt.show()
211
***************************************************************************
D:\anaconda\lib\site-packages\matplotlib\pyplot.py in scatter(x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, hold, data, **kwargs)
3468 vmin=vmin, vmax=vmax, alpha=alpha,
3469 linewidths=linewidths, verts=verts,
-> 3470 edgecolors=edgecolors, data=data, **kwargs)
3471 finally:
3472 ax._hold = washold
D:\anaconda\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs)
1853 "the Matplotlib list!)" % (label_namer, func.__name__),
1854 RuntimeWarning, stacklevel=2)
-> 1855 return func(ax, *args, **kwargs)
1856
1857 inner.__doc__ = _add_data_doc(inner.__doc__,
D:\anaconda\lib\site-packages\matplotlib\axes\_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)
4277 raise ValueError("c of shape {} not acceptable as a color "
4278 "sequence for x with size {}, y with size {}"
-> 4279 .format(c.shape, x.size, y.size))
4280 else:
4281 colors = None # use cmap, norm after collection is created
ValueError: c of shape (1, 300) not acceptable as a color sequence for x with size 300, y with size 300