首页 \ 问答 \ 在Python中,如何在不循环的情况下从另一个矩阵的值中分配稀疏矩阵的值?(In Python, how to assign the values of a sparse matrix from the values of another matrix without looping?)

在Python中,如何在不循环的情况下从另一个矩阵的值中分配稀疏矩阵的值?(In Python, how to assign the values of a sparse matrix from the values of another matrix without looping?)

我想做以下事情。

我有AA和x。 AA的形状和类型是

(1, 4) <class 'scipy.sparse.csr.csr_matrix'>

数字4只是一个例子。 在实际情况中,我有一个非常大的矩阵,如10000.x是

(4,) <type 'numpy.ndarray'>

现在我想要做的是用AA的值分配AA的值。

如果我做

AA=x

然后AA的类型将变为x,这不是我想要的。 我想让AA保持稀疏。 如果我做循环,当矩阵变大时似乎不可行。 你可以帮帮我吗? 谢谢。


I want to do the following.

I have AA and x. AA's shape and type are

(1, 4) <class 'scipy.sparse.csr.csr_matrix'>

the number 4 is just an example. In the real case, I have a very big matrix, like 10000. x's are

(4,) <type 'numpy.ndarray'>

Now what I want to do is to assign the values of AA with the values of x.

If I do

AA=x

then AA's type will change to x's, which isn't what I want. I want to keep AA as sparse. If I do looping, it seems not doable when the matrix becoming large. Could you help me? Thanks.


原文:https://stackoverflow.com/questions/26550972
更新时间:2023-07-29 10:07

最满意答案

你应该从中导入主题

import { Subject } from 'rxjs/Rx';  //full bundle

要么

import { Subject } from 'rxjs/Subject';//deep import , minimal import as required. 

you should import Subject from

import { Subject } from 'rxjs/Rx';  //full bundle

Or

import { Subject } from 'rxjs/Subject';//deep import , minimal import as required. 

相关问答

更多
  • 主题不存储搜索词框的值,它只是发出当前值的任何值 是每次有一个keyup事件。 主题根本不存储最后一个发射的值,因此如果要清除搜索框,则需要将输入框的值设置为''。 例如。 在您的英雄搜索组件中添加以下属性 @ViewChild('searchBox') searchBox: ElementRef; 然后在gotoDetail方法中: gotoDetail(hero: Hero): void { this.searchBox.nativeElement. ...
  • Subject或Observable不具有当前值。 当一个值被发出时,它被传递给订阅者,并且Observable被完成。 如果要具有当前值,请使用专为此目的设计的BehaviorSubject 。 BehaviorSubject保留最后发出的值,并立即将其发送给新订阅者。 它还有一个方法getValue()来获取当前值。 A Subject or Observable doesn't have a current value. When a value is emitted, it is passed to ...
  • 这取决于Rx.js的版本: 4.0包含一个.just方法; 5.0没有。 相反,使用.of方法。 喜欢这个: Rx.Observable.of(null).forEach(x => console.log(x)) That depends on the version of Rx.js: 4.0 includes a .just method; 5.0 doesn't. Instead, use the .of method. Like this: Rx.Observable.of(null).forEa ...
  • 你应该从中导入主题 import { Subject } from 'rxjs/Rx'; //full bundle 要么 import { Subject } from 'rxjs/Subject';//deep import , minimal import as required. you should import Subject from import { Subject } from 'rxjs/Rx'; //full bundle Or import { Subject } fro ...
  • 最新的RXJS发行版提供了分解模块,以减轻巨大的文件大小,Lodash。 导入rxjs/Rx (如另一个答案所示)将为您提供整个库,不建议使用。 相反,单独导入方法和运算符: 对于核心类,从其作用域模块导入类: import { Observable } from 'rxjs/Observable' 例如方法,在“添加”范围中使用实例范围: import 'rxjs/add/observable/fromEvent' (注意,没有要导入的析构对象 - 导入时会自动添加该方法) 对于运算符,从add/oper ...
  • 正如JB Nizet在评论中指出的那样,原因在于服务不是单身,即每个用户都得到一个新实例。 与角1相反,在A2服务不是单身人士。 为了让多个服务/组件共享该服务的一个实例,请将其放在父组件的@Component或@NgModule的提供程序中。 As JB Nizet pointed out in a comment, the reason was that the service was not a singleton, i.e. that every subscriber got a new insta ...
  • 您可以从yurzui创建的PLUNKER中看到,如果您恢复并暂停一切按预期工作,则只触发一次 。 问题是当你连续点击继续2次因为第一个订阅将在内存中丢失而只有第二个订阅将存储在this.subscription中时,对第一个订阅的访问将丢失,你无法取消订阅。 这更像是一个应用程序问题,而不是rxjs,如果订阅没有暂停,你不应该点击简历,所以你需要正确处理状态,这样的事情(从@yurzui plunker编辑): @Component({ selector: 'my-app', template: ` ...
  • 您看到的行为与RxJS的工作方式以及您的流的创建方式有关。 我们来看看WebsocketService : let observable = Observable.create( (obs: Observer) => { ws.onmessage = obs.next.bind(obs); obs对于每个订阅都是新的,但ws始终是相同的。 因此,当您在NotificationComponent再次订阅时, onmessage回调仅针对该订阅调用next回调。 因此只 ...
  • 我认为这不是与Gulp串联有关,而是与你使用的模块有关。 您应该使用以下之一: import {BehaviorSubject} from 'rxjs/Rx'; 要么 import {BehaviorSubject} from 'rxjs/subject/BehaviorSubject'; 实际上,RxJS不会直接注册rxjs模块,而是注册子模块(类似于rxjs/something )。 因此,SystemJS无法找到以前注册的模块,因此它会尝试从地址http://localhost:3000/rxjs ...
  • 我使用了angular-cli并生成了我的应用程序,它按预期工作。 请尝试下面的内容,如果有效,请告诉我。 import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; import {Observable} from 'rxjs';//Removed:/Observable //import 'rxjs/add/operator/map'; import {UtilsService} fr ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。