在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
最满意答案
你应该从中导入主题
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.
相关问答
更多-
rxjs主题 - 清楚?(rxjs Subject - clear?)[2021-12-28]
主题不存储搜索词框的值,它只是发出当前值的任何值 是每次有一个keyup事件。 主题根本不存储最后一个发射的值,因此如果要清除搜索框,则需要将输入框的值设置为''。 例如。 在您的英雄搜索组件中添加以下属性 @ViewChild('searchBox') searchBox: ElementRef; 然后在gotoDetail方法中: gotoDetail(hero: Hero): void { this.searchBox.nativeElement. ... -
如何获取RxJS Subject或Observable的当前值?(How to get current value of RxJS Subject or Observable?)[2023-05-21]
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 ... -
RxJS:如何导入Just(RxJS: How to import Just)[2022-02-26]
这取决于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的基本问题(Basic questions about Rxjs)[2024-02-14]
最新的RXJS发行版提供了分解模块,以减轻巨大的文件大小,Lodash。 导入rxjs/Rx (如另一个答案所示)将为您提供整个库,不建议使用。 相反,单独导入方法和运算符: 对于核心类,从其作用域模块导入类: import { Observable } from 'rxjs/Observable' 例如方法,在“添加”范围中使用实例范围: import 'rxjs/add/observable/fromEvent' (注意,没有要导入的析构对象 - 导入时会自动添加该方法) 对于运算符,从add/oper ... -
RxJS / Angular2:为什么我的主题用户不被调用?(RxJS / Angular2: Why is my subject subscriber not invoked?)[2022-03-11]
正如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 ... -
Angular2 - Rxjs主题在取消订阅后仍然运行两次(Angular2 - Rxjs Subject run twice even after unsubscribing)[2022-02-01]
您可以从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回调。 因此只 ... -
无法加载RxJs(Can not load RxJs)[2022-07-06]
我认为这不是与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 ...