self._Z = []为什么会出现错误

时间: 2023-09-25 21:12:00 浏览: 42
在代码中,self._Z = []是将_Z属性初始化为空列表,但是在getZ方法中,self._Z被赋值成为一个矩阵,所以可能会出现错误。 为了避免这种错误,应该在初始化时将self._Z初始化为空矩阵,而不是空列表,可以将类的初始化方法修改为以下内容: ```python def __init__(self): self._Z = np.mat([]) self._B = [] self._eigenVector = [] ``` 这样就可以避免在getZ方法中出现错误。同时,注意在其他方法中对self._Z的使用,需要先判断self._Z是否为空矩阵,避免出现使用空矩阵的错误。
相关问题

x = self.x_origin + (j + 0.5) * self.pixel_width y = self.y_origin + (i + 0.5) * self.pixel_height z = val self.iteSize += 1 return x, y, z dsm_path = 'C:\sanwei\jianmo\Productions\Production_2\Production_2_DSM_part_2_2.tif' dsm_data = gdal.Open(dsm_path) dsm_array = dsm_data.ReadAsArray() spiral_iterator = SpiralIterator(dsm_array,x=810,y=500) while spiral_iterator.hasNext(): x, y, z = spiral_iterator.get() print(f'Value at ({x},{y}):{z}')这段代码怎么改可以将打印的坐标保存为文档

你可以将打印出来的坐标以及对应的值写入到一个文本文件中,方法和上面类似。以下是修改后的代码示例: ```python import gdal class SpiralIterator: def __init__(self, array, x=0, y=0): self.array = array self.x_origin = x self.y_origin = y self.pixel_width = 1 self.pixel_height = 1 self.iteSize = 0 self.i = 0 self.j = 0 self.di = 0 self.dj = 1 self.width = array.shape[1] self.height = array.shape[0] def hasNext(self): return self.iteSize < self.width * self.height def get(self): val = self.array[self.i, self.j] x = self.x_origin + (self.j + 0.5) * self.pixel_width y = self.y_origin + (self.i + 0.5) * self.pixel_height self.iteSize += 1 self.i, self.j, self.di, self.dj = self.getNextIndex() return x, y, val def getNextIndex(self): if (self.i + self.di < 0 or self.i + self.di == self.height or self.j + self.dj < 0 or self.j + self.dj == self.width or self.array[self.i + self.di, self.j + self.dj] is None): self.di, self.dj = self.dj, -self.di return self.i + self.di, self.j + self.dj, self.di, self.dj dsm_path = r'C:\sanwei\jianmo\Productions\Production_2\Production_2_DSM_part_2_2.tif' dsm_data = gdal.Open(dsm_path) dsm_array = dsm_data.ReadAsArray() spiral_iterator = SpiralIterator(dsm_array, x=810, y=500) # 打开文件 with open('coordinates.txt', 'w') as f: while spiral_iterator.hasNext(): x, y, z = spiral_iterator.get() print(f'Value at ({x},{y}): {z}') # 将坐标和对应的值写入文件 f.write(f'({x},{y}): {z}\n') print('Done!') ``` 在这个例子中,我们使用了Python的with语句来打开文件,它可以自动管理文件的打开和关闭,避免了手动关闭文件时可能出现的错误。在while循环中,我们将打印的坐标和对应的值写入到了文件中。文件的名字可以根据你的需要自行修改。运行结束后,你可以在相应的目录下找到保存好的coordinates.txt文件。

VALID_MODULE_NAME = re.compile(r'[_a-z]\w*\.py$', re.IGNORECASE) class _FailedTest(case.TestCase): _testMethodName = None def __init__(self, method_name, exception): self._exception = exception super(_FailedTest, self).__init__(method_name) def __getattr__(self, name): if name != self._testMethodName: return super(_FailedTest, self).__getattr__(name) def testFailure(): raise self._exception return testFailure

这段代码是 Python 的 unittest 模块中的一部分。它定义了一个名为 _FailedTest 的类,这个类继承自 TestCase 类,用于测试用例执行失败时的处理。它包含一个 testFailure 方法,当测试用例执行失败时,该方法会被调用并且抛出 _exception 异常,_exception 是在 _FailedTest 的 __init__ 方法中传入的。这个类的作用是为了在测试用例执行失败时,能够更好地处理和报告错误。

相关推荐

程序执行提示AttributeError: 'point_cloud_generator' object has no attribute 'widthself',优化程序class point_cloud_generator(): def __init__(self, rgb_file, depth_file, save_ply, camera_intrinsics=[784.0, 779.0, 649.0, 405.0]): self.rgb_file = rgb_file self.depth_file = depth_file self.save_ply = save_ply self.rgb = cv2.imread(rgb_file) self.depth = cv2.imread(self.depth_file, -1) print("your depth image shape is:", self.depth.shape) self.width = self.rgb.shape[1] self.height = self.rgb.shape[0] self.camera_intrinsics = camera_intrinsics self.depth_scale = 1000 def compute(self): t1 = time.time() depth = np.asarray(self.depth, dtype=np.uint16).T # depth[depth==65535]=0 self.Z = depth / self.depth_scale fx, fy, cx, cy = self.camera_intrinsics X = np.zeros((self.width, self.height)) Y = np.zeros((self.width, self.height)) for i in range(self.width): X[i, :] = np.full(X.shape[1], i) self.X = ((X - cx / 2) * self.Z) / fx for i in range(self.height): Y[:, i] = np.full(Y.shape[0], i) self.Y = ((Y - cy / 2) * self.Z) / fy data_ply = np.zeros((6, self.width * self.height)) data_ply[0] = self.X.T.reshape(-1)[:self.widthself.height] data_ply[1] = -self.Y.T.reshape(-1)[:self.widthself.height] data_ply[2] = -self.Z.T.reshape(-1)[:self.widthself.height] img = np.array(self.rgb, dtype=np.uint8) data_ply[3] = img[:, :, 0:1].reshape(-1)[:self.widthself.height] data_ply[4] = img[:, :, 1:2].reshape(-1)[:self.widthself.height] data_ply[5] = img[:, :, 2:3].reshape(-1)[:self.widthself.height] self.data_ply = data_ply t2 = time.time() print('calcualte 3d point cloud Done.', t2 - t1)

bs_data = w_data[w_data['波束场景No'] == cross_data['波束场景No'][0]] 报错:Traceback (most recent call last): File "C:\Users\z84259074\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\indexes\base.py", line 3652, in get_loc return self._engine.get_loc(casted_key) File "pandas\_libs\index.pyx", line 147, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\index.pyx", line 176, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\hashtable_class_helper.pxi", line 7080, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas\_libs\hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: '波束场景No' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "D:\Users\z84259074\PycharmProjects\参数自优化\self_optimizing.py", line 127, in <module> data = optimizing() File "D:\Users\z84259074\PycharmProjects\参数自优化\self_optimizing.py", line 18, in __init__ self.optimizing_main() File "D:\Users\z84259074\PycharmProjects\参数自优化\self_optimizing.py", line 120, in optimizing_main self.child2=self.mutation_cdata(fitness_data,self.cross_data) File "D:\Users\z84259074\PycharmProjects\参数自优化\self_optimizing.py", line 86, in mutation_cdata bs_data = w_data[w_data['波束场景No'] == cross_data['波束场景No'][0]] File "C:\Users\z84259074\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\frame.py", line 3761, in __getitem__ indexer = self.columns.get_loc(key) File "C:\Users\z84259074\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\indexes\base.py", line 3654, in get_loc raise KeyError(key) from err KeyError: '波束场景No'

def unzip_infer_data(src_path,target_path): ''' 解压预测数据集 ''' if(not os.path.isdir(target_path)): z = zipfile.ZipFile(src_path, 'r') z.extractall(path=target_path) z.close() def load_image(img_path): ''' 预测图片预处理 ''' img = Image.open(img_path) if img.mode != 'RGB': img = img.convert('RGB') img = img.resize((224, 224), Image.BILINEAR) img = np.array(img).astype('float32') img = img.transpose((2, 0, 1)) # HWC to CHW img = img/255 # 像素值归一化 return img infer_src_path = '/home/aistudio/data/data55032/archive_test.zip' infer_dst_path = '/home/aistudio/data/archive_test' unzip_infer_data(infer_src_path,infer_dst_path) para_state_dict = paddle.load("MyCNN") model = MyCNN() model.set_state_dict(para_state_dict) #加载模型参数 model.eval() #验证模式 #展示预测图片 infer_path='data/archive_test/alexandrite_6.jpg' img = Image.open(infer_path) plt.imshow(img) #根据数组绘制图像 plt.show() #显示图像 #对预测图片进行预处理 infer_imgs = [] infer_imgs.append(load_image(infer_path)) infer_imgs = np.array(infer_imgs) label_dic = train_parameters['label_dict'] for i in range(len(infer_imgs)): data = infer_imgs[i] dy_x_data = np.array(data).astype('float32') dy_x_data=dy_x_data[np.newaxis,:, : ,:] img = paddle.to_tensor (dy_x_data) out = model(img) lab = np.argmax(out.numpy()) #argmax():返回最大数的索引 print("第{}个样本,被预测为:{},真实标签为:{}".format(i+1,label_dic[str(lab)],infer_path.split('/')[-1].split("_")[0])) print("结束") 以上代码进行DNN预测,根据这段代码写一段续写一段利用这个模型进行宝石预测的GUI界面,其中包含预测结果是否正确的判断功能

ERROR: test_pt_common_predict (__main__.TestCommonExecutor) ---------------------------------------------------------------------- Traceback (most recent call last): File "d_warehouse/vot/z_test/z_model/cv/pt_common.py", line 54, in test_pt_common_predict Mnist(self.data_dir, man="gcgS467j").b("0001").run() File "/django_scrapy/d_warehouse/vot/base/base.py", line 357, in run return self.do_run() File "/django_scrapy/d_warehouse/vot/data/dataset/cv/mnist.py", line 34, in do_run train_df = self.sqlc.createDataFrame(train_data_list) File "/usr/local/lib/python3.8/dist-packages/pyspark/sql/context.py", line 473, in createDataFrame return self.sparkSession.createDataFrame( # type: ignore[call-overload] File "/usr/local/lib/python3.8/dist-packages/pyspark/sql/session.py", line 1222, in createDataFrame self._jvm.SparkSession.setActiveSession(self._jsparkSession) File "/usr/local/lib/python3.8/dist-packages/py4j/java_gateway.py", line 1712, in __getattr__ answer = self._gateway_client.send_command( File "/usr/local/lib/python3.8/dist-packages/py4j/java_gateway.py", line 1036, in send_command connection = self._get_connection() File "/usr/local/lib/python3.8/dist-packages/py4j/clientserver.py", line 284, in _get_connection connection = self._create_new_connection() File "/usr/local/lib/python3.8/dist-packages/py4j/clientserver.py", line 291, in _create_new_connection connection.connect_to_java_server() File "/usr/local/lib/python3.8/dist-packages/py4j/clientserver.py", line 438, in connect_to_java_server self.socket.connect((self.java_address, self.java_port)) ConnectionRefusedError: [Errno 111] Connection refused

C:\Anaconda3\python.exe C:/pycharm.z/neo.py Traceback (most recent call last): File "C:\Anaconda3\lib\site-packages\py2neo\client\__init__.py", line 806, in acquire cx = self._free_list.popleft() IndexError: pop from an empty deque During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Anaconda3\lib\site-packages\py2neo\client\bolt.py", line 810, in _audit task.audit() File "C:\Anaconda3\lib\site-packages\py2neo\client\bolt.py", line 1303, in audit raise self._failure py2neo.errors.ClientError: [Security.Unauthorized] The client is unauthorized due to authentication failure. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\pycharm.z\neo.py", line 4, in <module> graph = Graph("bolt://localhost:7687", auth=("neo4j", "password")) File "C:\Anaconda3\lib\site-packages\py2neo\database.py", line 288, in __init__ self.service = GraphService(profile, **settings) File "C:\Anaconda3\lib\site-packages\py2neo\database.py", line 119, in __init__ self._connector = Connector(profile, **connector_settings) File "C:\Anaconda3\lib\site-packages\py2neo\client\__init__.py", line 960, in __init__ self._add_pools(*self._initial_routers) File "C:\Anaconda3\lib\site-packages\py2neo\client\__init__.py", line 982, in _add_pools pool = ConnectionPool.open( File "C:\Anaconda3\lib\site-packages\py2neo\client\__init__.py", line 649, in open seeds = [pool.acquire() for _ in range(init_size or cls.default_init_size)] File "C:\Anaconda3\lib\site-packages\py2neo\client\__init__.py", line 649, in seeds = [pool.acquire() for _ in range(init_size or cls.default_init_size)] File "C:\Anaconda3\lib\site-packages\py2neo\client\__init__.py", line 813, in acquire cx = self._connect() File "C:\Anaconda3\lib\site-packages\py2neo\client\__init__.py", line 764, in _connect cx = Connection.open(self.profile, user_agent=self怎么解决

(random.randint(0, bs_data[12]-1))*3+bs_data[8] 报错:Traceback (most recent call last): File "C:\Users\z84259074\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\indexes\base.py", line 3652, in get_loc return self._engine.get_loc(casted_key) File "pandas\_libs\index.pyx", line 147, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\index.pyx", line 176, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\hashtable_class_helper.pxi", line 7080, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas\_libs\hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 12 The above exception was the direct cause of the following exception: Traceback (most recent call last): File "d:\Users\z84259074\PycharmProjects\参数自优化\self_optimizing.py", line 128, in <module> data = optimizing() File "d:\Users\z84259074\PycharmProjects\参数自优化\self_optimizing.py", line 15, in __init__ self.optimizing_main() File "d:\Users\z84259074\PycharmProjects\参数自优化\self_optimizing.py", line 124, in optimizing_main self.child2=self.mutation_cdata(fitness_data,self.cross_data) File "d:\Users\z84259074\PycharmProjects\参数自优化\self_optimizing.py", line 92, in mutation_cdata print('cross_data[波束场景No]',bs_data[12]) File "C:\Users\z84259074\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\frame.py", line 3761, in __getitem__ indexer = self.columns.get_loc(key) File "C:\Users\z84259074\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\indexes\base.py", line 3654, in get_loc raise KeyError(key) from err KeyError: 12

最新推荐

recommend-type

MindeNLP+MusicGen-音频提示生成

MindeNLP+MusicGen-音频提示生成
recommend-type

WNM2027-VB一款SOT23封装N-Channel场效应MOS管

SOT23;N—Channel沟道,20V;6A;RDS(ON)=24mΩ@VGS=4.5V,VGS=8V;Vth=0.45~1V;
recommend-type

谷歌文件系统下的实用网络编码技术在分布式存储中的应用

"本文档主要探讨了一种在谷歌文件系统(Google File System, GFS)下基于实用网络编码的策略,用于提高分布式存储系统的数据恢复效率和带宽利用率,特别是针对音视频等大容量数据的编解码处理。" 在当前数字化时代,数据量的快速增长对分布式存储系统提出了更高的要求。分布式存储系统通过网络连接的多个存储节点,能够可靠地存储海量数据,并应对存储节点可能出现的故障。为了保证数据的可靠性,系统通常采用冗余机制,如复制和擦除编码。 复制是最常见的冗余策略,简单易行,即每个数据块都会在不同的节点上保存多份副本。然而,这种方法在面对大规模数据和高故障率时,可能会导致大量的存储空间浪费和恢复过程中的带宽消耗。 相比之下,擦除编码是一种更为高效的冗余方式。它将数据分割成多个部分,然后通过编码算法生成额外的校验块,这些校验块可以用来在节点故障时恢复原始数据。再生码是擦除编码的一个变体,它在数据恢复时只需要下载部分数据,从而减少了所需的带宽。 然而,现有的擦除编码方案在实际应用中可能面临效率问题,尤其是在处理大型音视频文件时。当存储节点发生故障时,传统方法需要从其他节点下载整个文件的全部数据,然后进行重新编码,这可能导致大量的带宽浪费。 该研究提出了一种实用的网络编码方法,特别适用于谷歌文件系统环境。这一方法优化了数据恢复过程,减少了带宽需求,提高了系统性能。通过智能地利用网络编码,即使在节点故障的情况下,也能实现高效的数据修复,降低带宽的浪费,同时保持系统的高可用性。 在音视频编解码场景中,这种网络编码技术能显著提升大文件的恢复速度和带宽效率,对于需要实时传输和处理的媒体服务来说尤其重要。此外,由于网络编码允许部分数据恢复,因此还能减轻对网络基础设施的压力,降低运营成本。 总结起来,这篇研究论文为分布式存储系统,尤其是处理音视频内容的系统,提供了一种创新的网络编码策略,旨在解决带宽效率低下和数据恢复时间过长的问题。这一方法对于提升整个系统性能,保证服务的连续性和可靠性具有重要的实践意义。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

【功率因数校正秘籍】:10个步骤提升电能利用率

![【功率因数校正秘籍】:10个步骤提升电能利用率](https://img-blog.csdnimg.cn/direct/829b6c5a308c40129620b20de2ebfcd9.png) # 1. 功率因数校正概述 功率因数是衡量交流电系统中有效功率与视在功率之比的指标,反映了电能利用的效率。当功率因数较低时,系统中的无功功率会增加,导致电能损耗、电压波动和电网容量浪费等问题。 功率因数校正是一种通过增加或减少无功功率来提高功率因数的技术。通过安装无功补偿设备,如电容器或电抗器,可以抵消感性或容性负载产生的无功功率,从而提高系统中的功率因数。功率因数校正不仅可以节约电能,还可以
recommend-type

``` if build_id then -- 单个屋子 else -- 所有屋子 end ```

在你的代码片段中,`build_id` 的存在与否决定了执行不同的逻辑。如果 `build_id` 为真(非空或非零),则执行针对单个屋子的代码;否则,执行针对所有屋子的代码。这种结构在 Lua 中已经相对简洁,但为了提高可读性和潜在的性能优化,你可以考虑以下几点: 1. **使用更明确的条件语句**:可以使用 `if build_id ~= nil` 替换 `if build_id then`,因为 `nil` 在 Lua 中被视为 `false`。 2. **逻辑封装**:如果两个分支的代码复杂度相当,可以考虑将它们抽象为函数,这样更易于维护和复用。 3. **避免不必要的布尔转换*
recommend-type

跨国媒体对南亚农村社会的影响:以斯里兰卡案例的社会学分析

本文档《音视频-编解码-关于跨国媒体对南亚农村群体的社会的社会学分析斯里兰卡案例研究G.pdf》主要探讨了跨国媒体在南亚农村社区中的社会影响,以斯里兰卡作为具体案例进行深入剖析。研究从以下几个方面展开: 1. 引言与研究概述 (1.1-1.9) - 介绍部分概述了研究的背景,强调了跨国媒体(如卫星电视、互联网等)在全球化背景下对南亚农村地区的日益重要性。 - 阐述了研究问题的定义,即跨国媒体如何改变这些社区的社会结构和文化融合。 - 提出了研究假设,可能是关于媒体对社会变迁、信息传播以及社区互动的影响。 - 研究目标和目的明确,旨在揭示跨国媒体在农村地区的功能及其社会学意义。 - 也讨论了研究的局限性,可能包括样本选择、数据获取的挑战或理论框架的适用范围。 - 描述了研究方法和步骤,包括可能采用的定性和定量研究方法。 2. 概念与理论分析 (2.1-2.7.2) - 跨国媒体与创新扩散的理论框架被考察,引用了Lerner的理论来解释信息如何通过跨国媒体传播到农村地区。 - 关于卫星文化和跨国媒体的关系,文章探讨了这些媒体如何成为当地社区共享的文化空间。 - 文献还讨论了全球媒体与跨国媒体的差异,以及跨国媒体如何促进社会文化融合。 - 社会文化整合的概念通过Ferdinand Tonnies的Gemeinshaft概念进行阐述,强调了跨国媒体在形成和维持社区共同身份中的作用。 - 分析了“社区”这一概念在跨国媒体影响下的演变,可能涉及社区成员间交流、价值观的变化和互动模式的重塑。 3. 研究计划与章节总结 (30-39) - 研究计划详细列出了后续章节的结构,可能包括对斯里兰卡特定乡村社区的实地考察、数据分析、以及结果的解读和讨论。 - 章节总结部分可能回顾了前面的理论基础,并预示了接下来将要深入研究的具体内容。 通过这份论文,作者试图通过细致的社会学视角,深入理解跨国媒体如何在南亚农村群体中扮演着连接、信息流通和文化融合的角色,以及这种角色如何塑造和影响他们的日常生活和社会关系。对于理解全球化进程中媒体的力量以及它如何塑造边缘化社区的动态变化,此篇研究具有重要的理论价值和实践意义。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

STM32单片机传感器接口应用:温度传感器、加速度传感器、陀螺仪,实战指南

![stm32单片机课程设计](http://embedded-lab.com/blog/wp-content/uploads/2015/03/Connection-Diagram.png) # 1. STM32单片机传感器接口概述** STM32单片机集成了丰富的传感器接口,为开发人员提供了便捷的传感器连接和应用方案。传感器接口类型多样,包括模拟接口、数字接口和专用接口,满足不同传感器的连接需求。 通过传感器接口,STM32单片机可以获取传感器数据,进行数据处理和分析,从而实现各种应用功能。传感器接口的配置和使用涉及到硬件电路设计和软件编程,需要深入理解传感器特性和接口协议。 # 2.
recommend-type

程序哪里有错误 fun(int *p1,int *p2) { int *p; *p = *p1; *p1 = *p2; *p2 = *p; }

这个函数`fun(int *p1, int *p2)`存在几个错误和潜在问题: 1. 变量声明与赋值:你试图通过`*p = *p1`来分配指针`p`的值,但实际上`p`是一个未初始化的指针,直接赋值可能会导致不确定的行为。正确的做法是先为`p`指向一个内存位置。 2. 临时变量:你的代码没有明确使用`p`这个临时变量。如果你想交换`p1`和`p2`所指向的值,应该使用指针的解引用操作,而不是将`*p`赋值给它们。 3. 指向不确定的数据:由于`p`没有被初始化,如果它指向的是栈上的临时空间,当函数结束时这些值可能会丢失,除非特别指定它指向堆中的数据。 修复后的代码可能如下所示: ```